2011-12-24 94 views
1

我有一個小的問題,改變對象的外觀和感覺。在我的應用程序中,我有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

回答

4

在改變外觀和感覺後,電網是否正常運行?

一些PLAF不畫它。


我正要熱鏈接到不同PLAFs表的一些示例圖像,this question。然後我意識到源代碼顯示了與您描述的相同的問題!

我可以在任何PLAF欄Nimbus中獲取單元格邊界/網格線。但是一旦選定了Nimbus,其他PLAF都不再顯示細胞邊界。 :(

+0

好吧,那好像是一個普遍的問題,我是以爲我做錯了什麼,然後我只使用setShowGrid。 – Andna 2011-12-24 12:10:24