JTable和外观 [英] JTable and Look and Feels

查看:96
本文介绍了JTable和外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

改变对象的外观和感觉时,我有一个小问题.在我的应用中,我有

I have small problem with changing look and feel of an object. In my app I have

public class JavaCommander extends JFrame

在这个类中,我有用自己的表模型构造的JTable.一切正常,但是正如我所说,当我想要改变外观时会遇到问题.在菜单栏中,我有一个具有可用外观的菜单.

and in this class I have JTable that is constructed with my own table model. Everything works fine, but as I said there is a problem when I want to change look and feel. In menu bar I have a menu with available look and feels.

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

因此,当我单击其中一个按钮时,应该会更改应用程序的外观.但是当我这样做时,一切都会改变,但是表中元素周围的网格丢失了,所以我需要添加

so when I click on one of the buttons it should change look and feel of my application. But when I do it everything changes but the grid around elements in table is missing so I needed to add

table.setShowGrid(true);

更改外观后,网格丢失是正常现象吗?

is it normal behavior that grid goes missing after changing look and feel?

推荐答案

更改外观后,网格丢失是正常现象吗?

is it normal behavior that grid goes missing after changing look and feel?

某些PLAF不会对其进行喷涂.

Some PLAFs do not paint it.

我正要在这个问题中热链接到不同PLAF中表格的一些示例图像.然后,我意识到源代码显示出与您描述的问题相同的问题!

I was just about to hot-link to some example images of tables in different PLAFs, in this question. Then I realized that source shows the same problem as you describe!

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

I can get cell borders/ grid-lines in any PLAF bar Nimbus. But once Nimbus has been selected, none of the other PLAFs show cell borders any longer. :(

这篇关于JTable和外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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