Getting and Displaying Swing Components From DataBase
hi,
I,m storing Swing Components in Database and i want the components like TextField and ComboBox to be created and Displayed while retrieving from database.
for example, 10 JLabels in one column along with that 10 (8 Textfields + 2 ComboBox) components in another Column. While retrieving im able to print 10 labels and 10 textfields in proper alignment.
like Label1 TextField1
Label2 TextFiled2
Label3 TextField3
------------------
------------------
What im doing is Im getting JLabels in an one array and JTextField in another array with help of for loop im displaying the Label ,TextField in the Panel. this is my coding
count is integer variable that having the total number of labels in the database.
---------------------------------------------------------------------------------------
JLabel[] label=new JLabel[count];
JTextField text[];
int k=60;
for(int i=0;i<label.length;i++)
{
text[i]=new JTextField();
text[i].setText("abcd");
text[i].setFont(textFieldFont);
text[i].setBounds(200, k, 100, 25);
k+=30;
}
-------------------------------------------------------------------
How could i create the JTextField , JComboBox simultaneously.
i had tried , ResultSet rs =Stmt.executeQuery("select component from
dg_components");
JComponent comp[]=new Jcomponent[count];
for(int i=0;i<label.length,i++)
{
if(rs.getString(1).equals("JTextField"))
{
comp[i]=
(JTextField)Class.forName("javax.swing.JTextField" ).getConstructor(new
Class[]{String.class}).newInstance(new Object[]{" "});
comp[i].setFont(textFieldFont);
comp[i].setBounds(200, k, 100, 25);
} else if(rs.getString(1).equals("JComboBox"))
{
comp[i]=
(JComboBox)Class.forName("javax.swing.JComboBox"). getConstructor(new
Class[]{String.class}).newInstance(new Object[]{" "});
// HERE IM NOT ABLE TO SET THE MODEL FOR THE JCOMBO BOX , BCZ IT
IS JCOMPONENT ..
}
}
CAN ANYONE TELL SOME OTHER WAY TO DO THIS......