use*_*754 6 java swing jtable nimbus
我正在使用Nimbus L&F.我正在尝试使用以下代码全局更改所有JTable的字体大小:
NimbusLookAndFeel nimbus = new NimbusLookAndFeel();
UIManager.setLookAndFeel(nimbus);
UIDefaults d = nimbus.getDefaults();
d.put("Table.font", new FontUIResource(new Font("SansSerif", Font.PLAIN, 18)));
Run Code Online (Sandbox Code Playgroud)
它正常工作,应用程序中的所有JTable行都使用新字体.我使用更大的字体大小使表格在大分辨率下更具可读性.
但问题是行高没有改变,导致字体被截断.我试过以下代码:
d.put("Table.contentMargins", new Insets(50,50,50,50));
d.put("Table:\"Table.cellRenderer\".contentMargins", new Insets(50,50,50,50));
Run Code Online (Sandbox Code Playgroud)
但它没有改变显示的表格中的任何内容.
我可以在不调用setRowHeight()每个JTable实例的情况下全局更改行高吗?
基本上,没有任何意图.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.
Run Code Online (Sandbox Code Playgroud)
从好的方面来看,像Nimbus这样的一些LAF尊重rowHeight的ui属性:
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);
Run Code Online (Sandbox Code Playgroud)