Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

java - Setting cell borders in JTable

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

enter image description here

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?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...