2012-03-12 98 views
3

我需要隱藏我的代碼中的狹縫窗格,如下圖所示。我不知道如何在Java Swing基本GUI中進行拆分窗格隱藏/取消隱藏。在我的代碼中,我將拆分窗格拆分爲兩個水平部分,然後將拆分窗格的右側部分拆分爲兩個垂直部分。我想要隱藏/取消隱藏分割窗格的左側部分。如何在基於Java Swing的GUI中隱藏/取消隱藏SplitPane

enter image description here

enter image description here

import java.awt.*; 
import java.awt.Event.*; 
import javax.swing.*; 

class DemoSwingDesign extends JFrame { 

    boolean b = false; 
    public static JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); 
    public static JSplitPane splitpane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true); 

    public DemoSwingDesign() { 
     JFrame frame = new JFrame("Split Pain"); 
     frame.setSize(300, 300); 
     frame.setVisible(true); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setDefaultLookAndFeelDecorated(true); 
     frame.setLayout(new GridLayout()); 
     //Defining Split Pane 


     //splitpane size 
     splitpane.setDividerLocation(150); 
     splitpane1.setDividerLocation(90); 
     splitpane.setContinuousLayout(true); 
     splitpane.setOneTouchExpandable(true); 

     JTabbedPane jtp = new JTabbedPane(); 
     jtp.setName("XRay"); 

     JTabbedPane jtp1 = new JTabbedPane(); 
     JTabbedPane jtp2 = new JTabbedPane(); 
     jtp1.setName("Set"); 
     jtp2.setName("OK"); 

     JPanel jp = new JPanel(new BorderLayout()); 

     JComponent Lefttabbedpane = new JTabbedPane(); 
     jp.add(jtp, -1); 
     Lefttabbedpane = jtp; 
     splitpane.add(splitpane1, "right"); 

     splitpane.setLeftComponent(new JScrollPane(jtp2)); 
     splitpane1.setTopComponent(new JScrollPane(jtp1)); 
     splitpane1.setBottomComponent(new JScrollPane(Lefttabbedpane)); 
     frame.add(splitpane); 
     frame.setVisible(true); 
    } 
} 

class Temp { 

    public static void main(String args[]) { 
     DemoSwingDesign d = new DemoSwingDesign(); 
    } 
} 
+0

看看這個鏈接 http://stackoverflow.com/questions/6836164/jsplitpane-is-there-a-way-to-show-hide-one-of-the-pane- http://stackoverflow.com/questions/4934499/how-to-set-jsplitpane-divider-collapse-expand-state – Nag 2012-03-12 05:49:39

回答

1

可能是你正在尋找這樣:JSplitPane.setOneTouchExpandable(boolean)

+0

以及功能我知道我想要一些如何完全隱藏拆分窗格,如上所示圖片 ,並允許該拆分窗格根據需要進行固定和取消固定 – Jony 2012-03-12 05:59:46

+0

這是否也是如此,將整個部分隱藏在jsplitpane中。我能看到的唯一區別就是*圖像中時尚的按鈕*。 – 2012-03-12 06:03:06

相關問題