I have two JTables that I would like displayed in one window. Currently I am able to display only one of the tables using:
JTable table1 = makeTable(1);
JTable table2 = makeTable(2);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollPane1 = new JScrollPane(table1);
JScrollPane scrollPane2 = new JScrollPane(table2);
frame.add(scrollPane1, BorderLayout.CENTER);
frame.validate();
frame.add(scrollPane1, BorderLayout.CENTER);
//frame.add(scrollPane2, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setVisible(true);
frame.validate();
What is the simplest way to display multiple tables, one on top of the other (though orientation is irrevelant) using Swing?
You can’t add both JTables to the same position in the BorderLayout.
What you can do is the following: