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 JTabbedPane有困难(错误压缩内容)_Java_User Interface_Swing - Fatal编程技术网

Java JTabbedPane有困难(错误压缩内容)

Java JTabbedPane有困难(错误压缩内容),java,user-interface,swing,Java,User Interface,Swing,我有一个用Java的Swing构建的GUI。我有一个拥有我所有控制权的JPanel: JPanel rightSidePanel = new JPanel(new GridBagLayout()); rightSidePanel.add(forwardKinematics, new GridBagConstraints()); 这个很好用。但是,我想添加一个选项卡式控件。不幸的是,添加选项卡会破坏布局: JTabbedPane tabs = new JTabbedPan

我有一个用Java的Swing构建的GUI。我有一个拥有我所有控制权的JPanel:

    JPanel rightSidePanel = new JPanel(new GridBagLayout());
    rightSidePanel.add(forwardKinematics, new GridBagConstraints());
这个很好用。但是,我想添加一个选项卡式控件。不幸的是,添加选项卡会破坏布局:

    JTabbedPane tabs = new JTabbedPane();
    tabs.addTab("Forward Kinematics", forwardKinematics);

    JPanel rightSidePanel = new JPanel(new GridBagLayout());
    rightSidePanel.add(tabs, new GridBagConstraints());
现在,
forwardkinetics
中的一些控件被严重压缩,而不是扩展到其全部大小。有没有什么方法可以让我指定控件可以扩展并占据它们想要的空间

我正在使用gridbag布局

下面是创建被压扁的UI控件(删除不相关的摘录)的代码:

我做错了什么


更新:我尝试使用
选项卡。setPreferredSize()
。这使得选项卡周围的区域更大(好像我在添加填充),但其中的内容仍然像以前一样被压扁。

默认构造的
GridBagConstraints
使用
填充
。在您的情况下,您可能希望同时使用


如果要使用
GridBagLayout
,请至少阅读。

您似乎缺少许多可能需要设置的GridBagLayout约束设置。您将所有内容都设置为gridy=2,这将它们都放在同一个单元格中


gridbaglayout的操作就像一个具有可配置行和列的表。

FYI,您不必为每个项目创建新的GridbagConstraints。如果它们有相似的内容,您可以重用它们。
add(control,gbc)
方法将复制约束本身。我在被压扁的表上为
fill
添加了
BOTH
,但它没有做任何事情。在选项卡式窗格中也使用这两种方法。
    panel.add(label, new GridBagConstraints());

    GridBagConstraints gbc = new GridBagConstraints();

    final DefaultTableModel model = new DefaultTableModel();
    model.addColumn("foo");
    model.addColumn("bar");
    final JTable table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);
    gbc = new GridBagConstraints();
    gbc.gridy = 2;
    gbc.ipady = 10;
    gbc.ipadx = 10;
    panel.add(scrollPane, gbc);

    final JComboBox comboBox = new JComboBox();

    gbc = new GridBagConstraints();
    gbc.gridy = 1;
    panel.add(comboBox, gbc);

    JButton makeNewButton = new JButton("Make new from current state");
    gbc = new GridBagConstraints();
    gbc.gridy = 1;
    panel.add(makeNewButton, gbc);

    JButton deleteButton = new JButton("Delete Current Keyframe");
    gbc = new GridBagConstraints();
    gbc.gridy = 2;
    panel.add(deleteButton, gbc);

    JButton playAll = new JButton("Play All");
    gbc = new GridBagConstraints();
    gbc.gridy = 2;
    panel.add(playAll, gbc);