--
Marie.
~~~~~~~~~~~~~~/\~~~~~~O-O~~~~~~~
A. Marie Alm, Sr. Software Engineer
0-In Design Automation, San Jose, Ca.
"Zero-In" http://www.0-In.com
Tel: 408.487.3608
~~~~~~~~~~~~~~\/~~~~~~~~~~~~~~~~
Alex Kravets wrote:
Hello,
Does anybody know how to create Swing components on the fly?
Here is the thing. I am reading a file in my applet that has information about potential Swing components I am going to need. Each line of that file describes characteristics of that components.
So, if my line reads:
==================================
button|test|JButton
text|sample text|JTextField
==================================I need automatically to generate two Swing components: JButton and JTextField.
I have a class that reads this file, breaks each line into tokens and initializes that class's private variables to all these tokens. So in the end, I have an array containing objects that have information:
name = button;
label = test;
componentType = JButton;Now, here is a problem, in my applet I get this array with objects, but how do I actually create Swing objects on the fly? I tried doing something like this:
String componentType = (String)tbData[0].getComponentType();
String label = (String)tbData[0].getLabel();
String compName = (String)tbData[0].getName();
if((componentType.equals("JButton"))){
componentsVector.add(JButton compName = new JLabel(label));It looks crazy, so does not work so far.
May be someone has any ideas on how to do this, I would appreciate any response.
thanks,
Alex