hi everyone
I want to draw a table dynamically based on user selection in the combo box.
so I have two components One Combo Box: which lists table name and Second a JTable which displays table data.
My Problem is that :
when page load first time based on the selected value of the combo box table is drawn but when I make another selection in the combo box table is not redrawn even though data is fetched from the database.
second problem is that I have put my JTable in the JScrollPane. But tables are wider and lengthy enough to contain in the ScrollPane properly.
Here Column Name and cell data is not displaying properly.
code I am writing is:
//This will redraw the table when user changes selection in the combo box
void jComboBox1_actionPerformed(ActionEvent e) {
Object combo= e.getSource();
String selectedTable="";
if(combo instanceof JComboBox)
{
JComboBox jcb = (JComboBox) combo;
//this will return selected table in the combo box
selectedTable = (String)jcb.getSelectedItem();
// this will return array list containg table column array and values array
ArrayList tablaData = new Customer().getTableData(selectedTable);
String tableColumn[] = (String[]) tablaData.get(0);
//System.out.print("column list:"+tableColumn.length);
Object data[][] = (Object[][]) tablaData.get(1);
//System.out.print("row list:"+data.length);
jTable1 = new JTable(data, tableColumn);
// jTable1.repaint();
pane = new JScrollPane(jTable1);
//pane.repaint();
System.out.println("table redrawn");
}
}
and I am adding this ScollPane to panel:
jPanel2.add(pane, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
Any Swing guru who can help me in redrawing the Table and Displaying the Column and Cell Data Properly.