JTable和外观和感觉

问题描述:

我有一个小的问题,改变对象的外观和感觉。在我的应用程序中,我有JTable和外观和感觉

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

是正常的行为网格改变外观和感觉后去失踪?

+1

Nimbus行为严重,没有在几个地方清理自己身后,表网格线只是其中之一 - 准备更多的污垢:-( – kleopatra 2011-12-25 12:25:32

在改变外观和感觉后,电网是否正常运行?

一些PLAF不画它。


我正要热链接到不同PLAFs表的一些示例图像,this question。然后我意识到源代码显示了与您描述的相同的问题!

我可以在任何PLAF栏Nimbus中获取单元格边界/网格线。但是一旦选定了Nimbus,其他PLAF都不再显示细胞边界。 :(

+0

好吧,那好像是一个普遍的问题,我是以为我做错了什么,然后我只使用setShowGrid。 – Andna 2011-12-24 12:10:24