Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么在我添加JLabel时GridBagLayout中的一个面板会扩展?_Java_User Interface_Jpanel_Gridbaglayout - Fatal编程技术网

Java 为什么在我添加JLabel时GridBagLayout中的一个面板会扩展?

Java 为什么在我添加JLabel时GridBagLayout中的一个面板会扩展?,java,user-interface,jpanel,gridbaglayout,Java,User Interface,Jpanel,Gridbaglayout,我正在尝试创建一个具有gridbaglayout的GUI 下面是我用gridbaglayout创建的GUI,它的大小非常完美 但是,当我尝试在“功能”面板中添加JLabel时,我的“功能”面板会自动扩展和更改GUI 请参见下面自动展开的面板 如何锁定所有面板,使其不改变大小并保持在此面板比率中 下面是我用来使用gridbaglayout调整GUI的源代码。我希望在调整框架大小或将组件添加到子面板时,确保所有面板保持相同的面板比率 frame = new JFrame("Cocoon"

我正在尝试创建一个具有gridbaglayout的GUI

下面是我用gridbaglayout创建的GUI,它的大小非常完美

但是,当我尝试在“功能”面板中添加JLabel时,我的“功能”面板会自动扩展和更改GUI

请参见下面自动展开的面板

如何锁定所有面板,使其不改变大小并保持在此面板比率中

下面是我用来使用gridbaglayout调整GUI的源代码。我希望在调整框架大小或将组件添加到子面板时,确保所有面板保持相同的面板比率

    frame = new JFrame("Cocoon");
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

    background = new JPanel();
    background.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    frame.getContentPane().add(background, BorderLayout.CENTER);

    filePanel = new FilesPanel();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.gridheight = 10;
    gbc.weightx = 0.2;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new Insets(10, 10, 10, 10);
    background.add(filePanel, gbc);

    beforePanel = new BeforePanel();
    afterPanel = new AfterPanel();

    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.gridwidth = 7;
    gbc.gridheight = 8;
    gbc.weightx = 0.5;
    gbc.weighty = 0.8;
    codes = new JSplitPane(JSplitPane.VERTICAL_SPLIT, beforePanel, afterPanel);
    codes.setOneTouchExpandable(true);
    codes.setResizeWeight(0.5);
    background.add(codes, gbc);

    feedBackPanel = new FeedbackPanel();
    gbc.gridx = 2;
    gbc.gridy = 8;
    gbc.gridwidth = 5;
    gbc.gridheight = 2;
    gbc.weightx = 0.5;
    gbc.weighty = 0.2;
    background.add(feedBackPanel, gbc);

    functionsPanel = new FunctionsPanel();
    gbc.gridx = 7;
    gbc.gridy = 0;
    gbc.gridwidth = 3;
    gbc.gridheight = 10;
    gbc.weightx = 0.3;
    gbc.weighty = 1.0;
    background.add(functionsPanel, gbc);

    frame.add(background);
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    frame.validate();
    frame.pack();
    frame.setVisible(true);
谢谢。

退房。基本上,没有简单的设置可以根据内容调整版面大小来获得GridBagLayout