如何全局更改JTable行高? [英] How to change JTable row height globally?

查看:52
本文介绍了如何全局更改JTable行高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Nimbus L&F.我正在尝试通过使用以下代码来全局更改所有JTable的字体大小:

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)));

它正在工作,应用程序中所有JTable的行都使用新字体.我正在使用更大的字体大小,以使表在较大的分辨率下更具可读性.

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.

是否可以在不为每个JTable实例调用setRowHeight()的情况下全局更改行高?

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

推荐答案

基本上,没有什么是故意的. BasicTableUI中的相关代码注释:

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.

从好的方面来说,有些LAF像f.i. Nimbus尊重rowHeight的ui属性:

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); 

这篇关于如何全局更改JTable行高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆