在java中设置combobox和textbox的固定宽度

在java中设置combobox和textbox的固定宽度,java,swing,Java,Swing,我有一个组合框,在同一个面板的右侧,我还有四个按钮。在面板的南部,我还有一个按钮,点击它会隐藏组合右边的四个按钮。结果,组合变宽了。我想在它的右侧添加一个标签和一个文本框,而不是本例中隐藏的四个按钮。但由于组合框变宽,右侧的空间不足以容纳文本框和标签。事实上,我可以看到整个标签框,但文本框非常窄,几乎看不见 我想请您帮助我如何设置组合的固定宽度,以及我添加的文本框 这是我现在拥有的代码: pPaint = new JPanel(); GridBagLayout pPaintL

我有一个组合框,在同一个面板的右侧,我还有四个按钮。在面板的南部,我还有一个按钮,点击它会隐藏组合右边的四个按钮。结果,组合变宽了。我想在它的右侧添加一个标签和一个文本框,而不是本例中隐藏的四个按钮。但由于组合框变宽,右侧的空间不足以容纳文本框和标签。事实上,我可以看到整个标签框,但文本框非常窄,几乎看不见

我想请您帮助我如何设置组合的固定宽度,以及我添加的文本框

这是我现在拥有的代码:

    pPaint = new JPanel();


    GridBagLayout pPaintLayout = new GridBagLayout();
    pPaintLayout.columnWidths = new int[] {7, 7, 7, 7, 7};
    pPaintLayout.rowHeights = new int[] {25};
    pPaintLayout.columnWeights = new double[] {100.0, 0.1, 0.1, 0.1, 0.1};
    pPaintLayout.rowWeights = new double[] {0.1};
    pPaint.setLayout(pPaintLayout);

    {
        cobSections = new JComboBox();
        cobSections.setRenderer(new    MapSectionItemRenderer());
        pPaint.add(cobSections, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
        GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
        new Insets(0, 0, 0, 0), 0, 0));
        cobSections.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
        cobSectionsActionPerformed(evt);
    }
      });
      }
          {
            lTimeInterval = new JLabel("interval");
            lTimeInterval.setVisible(false);
            pPaint.add(lTimeInterval, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0), 0, 0));
            }
          {

                tfInputTinter = new JTextField();
                tfInputTinter.setVisible(false);
                pPaint.add(tfInputTinter, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.NONE,
                        new Insets(0, 5, 0, 0), 0, 0));
            }

提前非常感谢

我用tfInputTinter=new JTextField(10)解决了这个问题;