如何在基于Java Swing的GUI中隐藏/取消隐藏SplitPane

时间:2012-03-12 05:46:09

标签: java swing jsplitpane

我需要在代码中隐藏Slit窗格,如下图所示。我不知道如何在Java Swing基础GUI中隐藏/取消隐藏分割窗格。在我的代码中,我将分割窗格分成两个水平部分,然后我将分割窗格的右分量分成两个垂直部分。我想隐藏/取消隐藏拆分窗格的左侧部分。

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();
    }
}

1 个答案:

答案 0 :(得分:1)