【问题标题】:JTable and Look and FeelsJTable 和外观
【发布时间】:2011-12-25 04:00:15
【问题描述】:

我在更改对象的外观和感觉方面遇到了小问题。在我的应用中,我有

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

更改外观后网格丢失是否正常?

【问题讨论】:

  • Nimbus 行为不端,在几个地方没有清理自己的后方,表格网格线只是其中之一 - 为更多的污垢做好准备:-(

标签: java swing jtable look-and-feel


【解决方案1】:

更改外观后网格丢失是否正常?

一些 PLAF 不对其进行绘制。


我正要在this question 中热链接到不同 PLAF 中表格的一些示例图像。然后我意识到源显示与您描述的相同的问题!

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

【讨论】:

  • 好吧,这似乎是一个普遍的问题,我在想我做错了什么。那我就用 setShowGrid 吧。
猜你喜欢
  • 2011-10-25
  • 1970-01-01
  • 1970-01-01
  • 2013-04-09
  • 2019-01-16
  • 1970-01-01
  • 2015-04-24
  • 2012-07-14
  • 1970-01-01
相关资源
最近更新 更多