When I call the method updateTable()
the table is displayed correctly but when I scroll the table horizontally some of the headers become distorted(wrong headers/headers overlap each other.).
I am using Netbeans what shall I do?
public void updateTable(String query)
{
try
{
String sql=query;
PreparedStatement pst=connectionVariable.prepareStatement(sql);
ResultSet res=pst.executeQuery();
myTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane scrollpane = new JScrollPane(myTable);
scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
myTable.setModel(DbUtils.resultSetToTableModel(res));
pst.close();
res.close();
}
catch(Exception e) { JOptionPane.showMessageDialog(null,""+e+"","Error Updating Table",JOptionPane.ERROR_MESSAGE); }
}
public loadTableAsPerSelection()
{
initComponents();
String load_table="Select columnnames from tablenames";
updateTable(load_table);
}