How to change jtable line height globally?

I am using Nimbus L & F. I am trying to change the font size globally for all JTable using the following code:

NimbusLookAndFeel nimbus = new NimbusLookAndFeel(); UIManager.setLookAndFeel(nimbus); UIDefaults d = nimbus.getDefaults(); d.put("Table.font", new FontUIResource(new Font("SansSerif", Font.PLAIN, 18))); 

It works, all JTable lines in the application use the new font. I use a larger font size to make the table more readable in high resolution.

But the problem is that the line height has not changed, which led to a truncation of the font. I tried the following code:

 d.put("Table.contentMargins", new Insets(50,50,50,50)); d.put("Table:\"Table.cellRenderer\".contentMargins", new Insets(50,50,50,50)); 

But this did not change anything in the displayed tables.

Is it possible to change the row height globally without calling setRowHeight() for each JTable instance?

+6
source share
1 answer

In principle, no intention. Corresponding code comment in BasicTableUI:

 // JTable original row height is 16. To correctly display the // contents on Linux we should have set it to 18, Windows 19 and // Solaris 20. As these values vary so much it too hard to // be backward compatable and try to update the row height, we're // therefor NOT going to adjust the row height based on font. If the // developer changes the font, it there responsability to update // the row height. 

On the bright side, some LAFs such as fi Nimbus respects the ui property for rowHeight:

 UIManager.put("Table.font", new FontUIResource(new Font("SansSerif", Font.PLAIN, 28))); // here simply the font height, need to do better int height = 28; UIManager.put("Table.rowHeight", height); 
+6
source

All Articles