问题
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