JTable table = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(500, 200));
JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 200));This example sets the preferred viewport size of the JTable directly without using a JScrollPane. The package library used for javax.swing JTable is the Java Foundation Classes (JFC) library, which is included in the Java Standard Edition (SE) platform.