1

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Andna
  • 6,539
  • 13
  • 71
  • 120
  • 1
    Nimbus is misbehaving severely, by not cleaning up behind itself at several places, table gridlines is just one of those - be prepared for more dirt :-( – kleopatra Dec 25 '11 at 12:25

1 Answers1

4

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

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Ok then, it seems it is a common problem, i was thinking that I done something wrong. I will just use setShowGrid then. – Andna Dec 24 '11 at 12:10