Simply what I want to do is to show some data in JTable when user click a button and it works correctly, however something weird is happening. When I click button at first time nothing happens but when I maximize frame, the table appears!
ActionListener
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
boolean state = external.isSelected();
DefaultTableModel model = new DefaultTableModel(ManhattanTable(values), Headers(values));
JTable table = new JTable(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
container.add(new JScrollPane(table));
table.setVisible(false);
if(state) {
PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream("output.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.setOut(out);
long start= System.currentTimeMillis();
Manhattan(values);
long end=System.currentTimeMillis();
out.println("time: "+(end-start)+" milliseconds");
out.println("Number of input data: "+values.size());
} else {
table.setVisible(true);
}
}
});
Anyone knows, why this strange behaviour?
After adding the table, call
container.revalidate()