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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2198754
  • 185
  • 3
  • 6
  • Did you tried this [solution](http://stackoverflow.com/questions/1783607/auto-adjust-the-height-of-rows-in-a-jtable) by camickr. – Amarnath Mar 22 '13 at 10:58
  • @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 table – kleopatra Mar 22 '13 at 11:02
  • Thanks for answering. This is really useful. Yes, what I need is default row height for all instances of table. – user2198754 Mar 22 '13 at 11:13

1 Answers1

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); 
kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • Please can you suggest me whether my approach is correct way or not? – Amarnath Mar 22 '13 at 11:05
  • This is the question to my answer, "Table.rowHeight" property allow me to set default row height for all JTable's in my application. – user2198754 Mar 22 '13 at 11:12
  • Thanks. +1 to question and answer. I always learn something from your comments and answers. – Amarnath Mar 22 '13 at 11:27
  • :) Appreciating your down-vote and removing the answer. [chuckles] I hope by deleting the answer I can stop ur polite cough .. :-) – Amarnath Mar 22 '13 at 12:19