2014-06-08 27 views
0

請大家,我有兩個分割窗格,說的是窗格A和窗格B,我在窗格A上放置了一個按鈕,這樣如果單擊該按鈕,窗格A被隱藏,窗格B變爲可見,但每次我嘗試這樣做,我得到一個錯誤,它說:在一個jframe上交換兩個不同的分割面

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Do not use this method 
    at net.java.dev.designgridlayout.DesignGridLayoutManager.removeLayoutComponent(DesignGridLayoutManager.java:122). 

回答

1

該說明是絕不足以給出一個深刻的答案。但基於documentation of the method that causes the error,似乎從這種佈局中刪除組件是不受支持的。

您可以使用不同的佈局管理器。也許CardLayout可能會有所幫助。有疑問的是,應該始終可以引入額外的容器。我將在這裏寫生的想法,雖然沒有人知道你的代碼是什麼樣子:

class GUI { 
    private JPanel containerA = new JPanel(new GridLayout(1,1)); 

    void init() { 
     ... 
     // Here "grid" is the component that has the DesignGridLayout: 
     grid.add(containerA); 
     containerA.add(splitPaneA); 
    } 

    void whenTheButtonIsClicked() { 
     containerA.removeAll(); 
     containerA.add(splitPaneB); 
     containerA.revalidate(); 
    } 
} 
+0

我的代碼看起來像這樣@marco .. – chrisgeeq

+0

如果(event.get源()==按鈕){ GET pass = new String(pass field.get Password()); get text = text field.get Text();如果(()get text.equals(「」))||(get pass.equals(「」))){ invalid_input.set Text(「PLEASE INPUT DETAILS」); } else if(!「」。equals(get text)||(!「」。equals(get pass))){ pane.set Visible(false); q panel.set J splitPane()。set Visible(true); } }} } @ – chrisgeeq

+0

您user3537071應該刪除這個(不可讀)評論,並嘗試據此編輯你的問題。 (而且,對於未來的問題,最好從一開始就提供相關的代碼 - 最好是以http://stackoverflow.com/help/mcve的形式提供。這真的有助於快速獲得好的和有幫助的答案) – Marco13

相關問題