JTable和外观

时间:2011-12-24 10:48:02

标签: java swing jtable look-and-feel

改变对象的外观和感觉时遇到小问题。在我的应用程序中我有

public class JavaCommander extends JFrame

在这个类中我有JTable,它是用我自己的表模型构建的。一切都很好,但正如我所说,当我想改变外观和感觉时,有一个问题。在菜单栏中,我有一个可用的外观和感觉的菜单。

menuBar=new JMenuBar();
    JMenu lookMenu=new JMenu("Look and Feel");

    UIManager.LookAndFeelInfo[] info= UIManager.getInstalledLookAndFeels();
    ButtonGroup group=new ButtonGroup();

    for (int i=0;i<info.length;++i)
    {
        JRadioButtonMenuItem but=new JRadioButtonMenuItem(info[i].getClassName());
        but.addActionListener(new ActionListener()
        {

            public void actionPerformed(ActionEvent e) 
            {
                try {
                    UIManager.setLookAndFeel(e.getActionCommand());
                    SwingUtilities.updateComponentTreeUI(JavaCommander.this);
                    table.setShowGrid(true);
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();
                } catch (InstantiationException e1) {
                    e1.printStackTrace();
                } catch (IllegalAccessException e1) {
                    e1.printStackTrace();
                } catch (UnsupportedLookAndFeelException e1) {
                    e1.printStackTrace();
                }

            }

        });
        lookMenu.add(but);
        group.add(but);
    }
    menuBar.add(lookMenu);

所以当我点击其中一个按钮时,它应该改变我的应用程序的外观。但是当我这样做时,所有内容都会发生变化,但表格中的元素网格缺失,所以我需要添加

table.setShowGrid(true);

改变外观后感觉网格缺失是否正常?

1 个答案:

答案 0 :(得分:4)

  

改变外观后感觉网格缺失是否正常?

有些PLAF没有画它。


我正准备热链接到this question中不同PLAF中的表的一些示例图像。然后我意识到源代码显示的问题和你描述的一样!

我可以在任何PLAF栏Nimbus中获得单元格边框/网格线。但是一旦选择了Nimbus,其他PLAF都不再显示细胞边界。 :(

相关问题