Alright so I'm creating a JTable
with fake stocks and corresponding numbers equal to their value. It currently looks like this:
As you can see, everything is properly spaced and its code is relatively simple:
table = new JTable(data, columnNames);
table.setModel(new DefaultTableModel(
new Object[][] {
{"Webnet", "11"},
{"Clone Corp", "12"},
{"City Bank", "15"},
{"Herbmart", "14"},
{"Digital Systems", "17"},
{"National Airlines", "10"},
{"State Power", "16"},
{"Parkland", "13"},
},
new String[] {
"Stock", "Price"
}
));
table.setBorder(new MatteBorder(2, 2, 2, 2, (Color) Color.GRAY));
All that does is set the columns and rows and the border. Very simple. However, as you can see, with both of the columns the same width, there's a lot of unnecessary whitespace in the rows with numbers which would not become large enough to require that. How can I make those smaller without changing the other row's size?