【发布时间】: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