我一直在使用Java Swing中的Jsplit Pane合作,我试图在一个主框架中设置水平和垂直拆分窗格,首先是在左右面板上划分主框架,然后将其划分为右面板分为底部和顶部面板。我成功地将主框架分为左右面板,但是之后,它不能很好地分为底部和顶部面板,它将右面板拆下分裂成底部和顶部..有人可以帮助我解决这个问题吗?
拆分窗格的代码:
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, panel);
add(split, BorderLayout.CENTER);
split.setDividerLocation(250);
panel.setBackground(Color.RED);
JPanel gPanel=new JPanel();
gPanel.setMinimumSize(new Dimension(30,30));
JPanel dPanel=new JPanel();
dPanel.setMinimumSize(new Dimension(30,30));
split2=new JSplitPane(JSplitPane.VERTICAL_SPLIT,gPanel,dPanel);
panel.add(split2,BorderLayout.CENTER);
split2.setDividerLocation(250);
gPanel.setBackground(Color.BLUE.brighter());
如果我正确理解,则需要筑巢窗格,因此代码将是:
JPanel top = new JPanel();
JPanel bottom = new JPanel();
JSplitPane right = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, bottom);
JPanel left = new JPanel();
JSplitPane horizontal = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
frame.add(horizontal, BorderLayout.CENTER);