JTable and Look and Feels

空扰寡人 提交于 2019-12-24 08:24:21

问题


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

public class JavaCommander extends JFrame

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?


回答1:


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

Some PLAFs do not paint it.


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!

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. :(



来源:https://stackoverflow.com/questions/8624040/jtable-and-look-and-feels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!