2013-02-20 106 views
0

我只是有這個問題:的JPanel comonents無需點擊鼠標

public class Sales extends JPanel{ 
    ArrayList<JPanel> panes; 
    ArrayList<String> tabs; 
    JTabbedPane tp; 
    public Sales(Dimension d){ 
     setSize(d); 
     setLayout(null); 
     tp = new JTabbedPane(); 
     Font f = new Font("Arial",Font.PLAIN,32); 
     tp.setFont(f); 
     for(Menu menu : FileManager.menus){ 
      JPanel tmp = new JPanel(); 
      /*int s = (int) Math.ceil(Math.sqrt(menu.products.size())); 
      tmp.setLayout(new GridLayout(s,s)); 
      System.out.println("size" + s); 
      for(Product p : menu.products){ 
       p.setFont(f); 
       tmp.add(p); 
      }*/ 
      tp.addTab(menu.name,null,tmp,"What is this?"); 
     } 
     tp.setBounds(0,0,getWidth(),getHeight()); 
     add(tp); 
    } 
} 

這裏銷售的只是添加到一個簡單的JFrame:

public Main(){ 
     super("HoboGames Pos System"); 
     setUndecorated(true); 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setVisible(true); 
     GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this); 
     sale = new Sales(getSize()); 
     add(sale); 
    } 

一切正常,除了組件唐直到窗口由於點擊或更新而被更新時才繪製。所以它是一個空白的屏幕,直到你點擊的東西。(對不起,我削減了一些東西,如使其全屏幕...)

+0

請編輯您的問題以包含展示您描述的問題的[sscce](http://sscce.org/)。 – trashgod 2013-02-20 23:50:10

回答

2

它們不更新,因爲你已經完成之前窗口可見添加組件。

嘗試類似...

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this); 
sale = new Sales(getSize()); 
add(sale); 
setVisible(true); 

此外,也可以在框架上調用revalidaterepaint你添加完組件後,但說實話,這是簡單的第一種方式。

旁註

在組件上使用setSize強烈反對,你應該依靠適當的佈局管理,像BorderLayout做出關於組件的大小決定。

+0

我這樣做了,它並沒有真正的工作,但我只是通過重繪()後設置它可見,並修復它。 – csga5000 2013-02-20 23:55:22

+0

@ csga5000:然後你需要使用佈局和'pack()'封閉的'Window'。 – trashgod 2013-02-21 00:03:30