不需要的按钮

时间:2018-02-11 09:45:04

标签: java swing user-interface jsplitpane

任何人都可以告诉我为什么按钮出现在底部面板中我怎么能摆脱它们?

我打算用三种不同的颜色创建三个不同的面板,最后我得到一种颜色和两个按钮。

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;


public class Mywindow extends JFrame {

public Mywindow() {
    setTitle("My window");
    setLayout(new BorderLayout());
    setSize(500, 500);

    JPanel leftPanel = new JPanel();
    leftPanel.setBackground(Color.BLUE);
    JPanel centerPanel = new JPanel();
    centerPanel.setBackground(Color.CYAN);
    JPanel rightPanel = new JPanel();
    rightPanel.setBackground(Color.GREEN);

    JSplitPane sp=new JSplitPane();
    JSplitPane sp2=new JSplitPane();

    sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, centerPanel, sp);
    sp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftPanel, rightPanel);

    add(sp, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}

public static void main(String[] args) {
        new Mywindow();
    }    
}

1 个答案:

答案 0 :(得分:1)

替换它:

JSplitPane sp=new JSplitPane();
JSplitPane sp2=new JSplitPane();

//adding a split pane to itself will bring no good
sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, centerPanel, sp); 
sp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftPanel, rightPanel);

有了这个:

JSplitPane sp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftPanel, rightPanel);
JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, centerPanel, sp2);

要看到这个:

enter image description here