Imports and table model left as an exercise to the user of this code. Also, the panel layout is arbitrarily chosen for simplicity.
public class JTableDisplay {
public JTableDisplay() {
JFrame frame = new JFrame("JTable Test Display");
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTable table = new JTable();
JScrollPane tableContainer = new JScrollPane(table);
panel.add(tableContainer, BorderLayout.CENTER);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new JTableDisplay();
}
}
The scroll pane is fairly important to note. Without it, your table won't have a header or scroll if the content becomes larger than the display.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…