在JTable中设置单元格边框 [英] Setting cell borders in JTable

查看:916
本文介绍了在JTable中设置单元格边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JTable ,我只显示水平线来分隔每个表行。在Windows 8中,线条显示,但在Mac OS X中,它们没有。我在一个自定义单元格渲染器中为表中的所有单元格使用 JLabel ,并为 JLabel 为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中设置单元格边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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