【发布时间】:2017-04-01 23:21:04
【问题描述】:
我想要 3 个可水平调整大小的 JPanel。它工作正常,但我无法设置第一个 JSlitPane 的位置:sp.setDividerLocation(.3); 不起作用。
public class JSplitPanelProva extends JFrame {
public JSplitPanelProva() {
this.setLayout(new BorderLayout());
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.HORIZONTAL_SPLIT, leftPanel, centerPanel);
JSplitPane sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, rightPanel);
sp.setOneTouchExpandable(true);
sp2.setOneTouchExpandable(true);
this.add(sp2, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(1000, 600);
this.setVisible(true);
sp.setDividerLocation(.3);
sp2.setDividerLocation(.6);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new JSplitPanelProva();
}
}
【问题讨论】: