java - GridBagLayout - JFormattedTextFields 太少了?

标签 java eclipse swing user-interface gridbaglayout

我正在 SWING 中编写 gui 代码:

    JLabel tLabel1 = new JLabel("Name: ");
    JFormattedTextField tTextField1 = new JFormattedTextField();
    textBoxes.add(tTextField1);
    JLabel tLabel2 = new JLabel("Maximaler Preis: ");
    JFormattedTextField tTextField2 = new JFormattedTextField();
    textBoxes.add(tTextField2);

        GridBagLayout tLayout = new GridBagLayout();
        mainFrame.getContentPane().setLayout(tLayout);
//      tLayout).setAutoCreateGaps(true);
//      tLayout.setAutoCreateContainerGaps(true);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.WEST;

        mainFrame.add(new JLabel("Geben sie bitte die Kriterien für die Suche an:"), gbc);

        gbc.gridwidth = 1;
        gbc.gridy++;
        mainFrame.add(tLabel1, gbc);
        gbc.gridy++;
        mainFrame.add(tLabel2, gbc);
        gbc.gridy++;
        mainFrame.add(tLabel3, gbc);
        gbc.gridy++;
        mainFrame.add(tLabel4, gbc);

        gbc.gridx++;
        gbc.gridy = 1;
        mainFrame.add(tTextField1, gbc);
        gbc.gridy++;
        mainFrame.add(tTextField2, gbc);
        gbc.gridy++;
        mainFrame.add(tTextField3, gbc);    
        gbc.gridy++;
        mainFrame.add(tCombo, gbc);
        gbc.gridy++;
        mainFrame.add(searchButton, gbc);

        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.HORIZONTAL;

        mainFrame.add(tTable, gbc); 
        mainFrame.setSize(800, 500);
        mainFrame.pack();

我的文本字段如下所示:

|

如何在 GridBagLayout 中给它们指定宽度?

最佳答案

关于java - GridBagLayout - JFormattedTextFields 太少了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795978/

相关文章:

java - Apache Tomcat 9 无法启动(eclipse)

java - Maven Spring Jar 项目 java.lang.ClassNotFoundExceptiona

java - JTable 无法添加滚动条

java - Swing - UI 重新验证未发生

java - Java 中图像的组合重新缩放和颜色减少?

java - 重定向输出的shell脚本

java - 如何获取URL中的数字?

Java - Ackley 测试函数

c - 作为文本文件的版本控制?

java - 是否可以将 JComponent 及其所有子组件绘制到另一个组件?