问题描述
我有一个 JTable
,我只显示水平线来分隔每个表行。在Windows 8中,线条显示,但在Mac OS X中,它们没有。我在一个自定义单元格渲染器中为表中的所有单元格使用 JLabel
,并为 JLabel $添加了一个遮罩边框c $ c>为Mac OS X纠正此问题。但是,它看起来不正确,因为如果仔细查看下面的屏幕截图,您可以看到水平线断开(即不连续),其中一列结束并且另一个开始。 (仔细查看英文和笔记栏。)
如何为表格中的所有单元格添加边框,使其看起来像下面的Windows 8屏幕截图中的那个? / p>
Mac OS X上的 TableUI
委托设置 Table.background
和 Table.gridColor
到 Color.white
,使网格有效不可见。您可以像这样更改网格颜色:
UIManager.put(Table.gridColor,new ColorUIResource(Color.gray) );
EventQueue.invokeLater(new Runnable(){
@Override
public void run(){
//构建你的GUI
}
});
I have a JTable
, and I only show horizontal lines to separate each table row. In Windows 8, the lines show, but in Mac OS X, they don't. I am using a JLabel
in a custom cell renderer for all of the cells in the table, and I added a matte border to the JLabel
to correct this problem for Mac OS X. However, it doesn't look right because if you look closely in the screenshot below, you can see that the horizontal line is broken (i.e. not contiguous) where one column ends and the other begins. (Look closely between the English and Notes columns.)
How do I add a border to all of the cells in the table such that it looks like the one in the Windows 8 screenshot below?
The TableUI
delegate on Mac OS X sets both Table.background
and Table.gridColor
to Color.white
, making the grid effectively invisible. You can change the grid color like this:
UIManager.put("Table.gridColor", new ColorUIResource(Color.gray));
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// construct your GUI
}
});
这篇关于在JTable中设置单元格边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!