Trying to have a JTable inside a JScrollPane. But the problem is, every time I add another row to the table, the JFrame increases in size, height-wise (screenshot below for reference). I don't want it to do this. Obviously, since it's in a scroll pane, if I keep adding rows to the table, I want a scrollbar to actually be shown and used to scroll down to see the lower values in the table.
Screenshot: http://i.imgur.com/dUqQW7N.jpg
Code:
String[] columns = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
Object[][] data = {
{"Kathy", "Smith", "Snowboarding", 5, false},
{"John", "Doe", "Rowing", 3, true},
{"Sue", "Black", "Knitting", 2, false},
{"Jane", "White", "Speed reading", 20, true},
{"Joe", "Brown", "Pool", 10, false}
};
searchBox = new JTextField();
searchButton = new JButton();
rentCarButton = new JButton();
rentedCarsButton = new JButton();
table = new JTable(data, columns);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
scrollPane = new JScrollPane(table);
Any help would be greatly appreciated.