Wednesday, 2 April 2014

Java: Changing JTable's Background Color in a JScrollpane

If a JTable is being displayed in a JScrollPane and the table shows only few rows of data and the rest of table is empty. Changing the color of the empty table space wont work with setBackground(...). To do this

JTable#setFillsViewportHeight(true);

or

JScrollPane#getViewport().setBackground(JTable#getBackground());

or you can to fits JScrollPanes JViewport to the JTables view by

JTable#setPreferredScrollableViewportSize(JTable#getPreferredSize());

This solution is taken from stackoverflow.

No comments:

Post a Comment