Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change JTable row height globally?

I'm using Nimbus L&F. I'm trying to change font size globally for all JTable by 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's working, all JTable's rows in the application are using the new font. I'm using bigger font size to make table more readable in large resolution.

But the problem is row height didn't changed, causing the font to be truncated. I've 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 it didn't change anything in the displayed tables.

Can I change row height globally without calling setRowHeight() for each JTable's instance?

like image 774
user2198754 Avatar asked Mar 22 '13 10:03

user2198754


1 Answers

Basically, there is nothing by intention. The relevant code-comment in BasicTableUI:

// JTable's 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's 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's there responsability to update
// the row height.

On the bright side, some LAFs like f.i. Nimbus respect a 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); 
like image 121
kleopatra Avatar answered Nov 05 '22 00:11

kleopatra