我正在尝试让3个面板重新调整大小,我为它编写了代码。它应该工作。但事实并非如此。我正在制作3个JPanel
组件,将它们添加到两个拆分窗格中,第一个拆分窗格包含中间面板和右侧面板。第二个分割窗格保持相同的中间面板和左侧面板,因此中间面板位于两个分割窗格中。
如果你能帮助我解决这个问题,我将非常感激。
public class FinalProjectTestCase1 {
public static void main(String[] args)
{
Frame frame = new Frame();
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
}
}
class Frame extends JFrame
{
JPanel LeftPanel;
JPanel MiddlePanel;
JPanel RightPanel;
Frame()
{
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(700,700));
MiddlePanel= new JPanel();
MiddlePanel.setLayout(new GridLayout());
RightPanel= new JPanel();
RightPanel.setLayout(new GridLayout());
RightPanel.setPreferredSize(new Dimension(250,700));
LeftPanel= new JPanel();
LeftPanel.setLayout(new GridLayout());
LeftPanel.setPreferredSize(new Dimension(250,700));
JButton MiddlePanelb= new JButton("MiddlePanel");
MiddlePanel.add(MiddlePanelb);
JButton leftPanelb= new JButton("leftPanelb");
LeftPanel.add(leftPanelb);
JButton RightPanelb= new JButton("RightPanelb");
RightPanel.add(RightPanelb);
JSplitPane RightSplitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,(MiddlePanel),(RightPanel));
JSplitPane LeftSplitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,(LeftPanel),(MiddlePanel));
this.add(MiddlePanel);
this.add(RightSplitPane,BorderLayout.EAST);
this.add(LeftSplitPane,BorderLayout.WEST);
}
}