[英]How to change JTable row height globally?
我正在使用 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)));
它正在工作,應用程序中所有 JTable 的行都使用新字體。 我使用更大的字體大小使表格在大分辨率下更具可讀性。
但問題是行高沒有改變,導致字體被截斷。 我試過以下代碼:
d.put("Table.contentMargins", new Insets(50,50,50,50));
d.put("Table:\"Table.cellRenderer\".contentMargins", new Insets(50,50,50,50));
但它沒有改變顯示的表格中的任何內容。
我可以在不為每個 JTable 的實例調用setRowHeight()
的情況下全局更改行高嗎?
基本上,沒有什么是故意的。 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.
從好的方面來說,像 fi 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.