How to change JTable row height globally?
Asked Answered
P

1

6

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?

Piddock answered 22/3, 2013 at 10:26 Comment(3)
Did you tried this solution by camickr.Ramberg
@che don't think so - that question was about individual row heights in one instance of a concrete table. This question (as I understand it at least :-) is about the default row height for all instances of tableNonalignment
Thanks for answering. This is really useful. Yes, what I need is default row height for all instances of table.Piddock
N
6

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); 
Nonalignment answered 22/3, 2013 at 11:0 Comment(4)
Please can you suggest me whether my approach is correct way or not?Ramberg
This is the question to my answer, "Table.rowHeight" property allow me to set default row height for all JTable's in my application.Piddock
Thanks. +1 to question and answer. I always learn something from your comments and answers.Ramberg
:) Appreciating your down-vote and removing the answer. [chuckles] I hope by deleting the answer I can stop ur polite cough .. :-)Ramberg

© 2022 - 2024 — McMap. All rights reserved.