是的,你也可以做到這一點,以這樣的方式
JTabbedPane preupdatetab = new JTabbedPane();
preupdatetab.setForeground(new Color(255,0,0).darker());
preupdatetab.setBounds(30,15,930,300);
preupdate.add(preupdatetab);
precomplete.setLayout(null);
preupdatetab.add(precomplete,"Complete Change");
preonce.setLayout(null);
preupdatetab.add(preonce,"Qty Change");
changelocationpanel = new JPanel();
changelocationpanel.setLayout(null);
preupdatetab.add(changelocationpanel,"Change Location");
changesaleprice = new JPanel();
changesaleprice.setLayout(null);
preupdatetab.add(changesaleprice,"Change Sale Price");
changebookprice = new JPanel();
changebookprice.setLayout(null);
preupdatetab.add(changebookprice,"Change Book Price");
changevendor = new JPanel();
changevendor.setLayout(null);
preupdatetab.add(changevendor,"Change Vendor");
changeitemname = new JPanel();
changeitemname.setLayout(null);
preupdatetab.add(changeitemname,"Change Item Name");
的其他變量全局聲明JLabel的,所以不要混淆 和下面的圖片會清除你更多關於這一點。
如果你有一個單獨的文件,那麼你沒有將MVC和OOP概念應用到正確的....並且看到[使用多個JFrames,好/壞實踐?](http:// stackoverflow。 com/questions/9554636/multi-jframes-good-or-bad-practice)(BAD)也會查看[Card Layout](https://docs.oracle.com/javase/)教程/ uiswing/layout/card.html)在視圖之間切換而不是改變可見性 – Frakcool
感謝您的提示,我會立即看看卡片佈局:D我有多個java文件,每個文件處理不同的功能,但只有1文件與所有的GUI和事件,這是越來越難以維護所有的事件代碼和添加組件和一切在一個單一的Java文件,所以我問,如果我寧願做多個jframes其他文件只處理插入和其他這種operati但是那裏的對象是在那個jframe文件本身中創建的 –
不知道我完全理解這裏的層次結構,但是似乎主菜單中的每個項目可能有多個子項目?那些反過來有孩子嗎?也許是一個JTree--這將允許同時查看父級和子級操作 - 然後使用「CardLayout」根據樹節點上的點擊在視圖之間切換。 – copeg