WindowBuilder定位错误

时间:2018-07-27 13:29:27

标签: java interface windowbuilder

最近,我决定使用WindowBuilder创建一个接口。 多亏了预览功能,我才能看到我的应用程序的外观。但是当我编译程序时,它是这样的:

顶部是所需结果,底部是获得的结果 enter image description here

我不明白我的问题是什么。为什么每个组件都这样反应。最初,我曾经使用FormLayout来解决相同的问题,但是我没有印象是这将解决它。这是我的代码:

package IHM;

import java.awt.EventQueue;

import javax.swing.JFrame;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.FormSpecs;
import javax.swing.JTextField;
import javax.swing.JButton;
public class Test {

    private JFrame frame;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JButton btnSelection;
    private JTextField textField_3;
    private JButton btnCommencer;
    private JTextField textField_4;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Test window = new Test();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public Test() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setResizable(false);
        frame.setBounds(100, 100, 600, 350);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(new FormLayout(new ColumnSpec[] {
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),},
            new RowSpec[] {
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,}));

        textField = new JTextField();
        frame.getContentPane().add(textField, "3, 6, 3, 1, fill, default");
        textField.setColumns(10);

        textField_1 = new JTextField();
        frame.getContentPane().add(textField_1, "8, 6, 3, 1, fill, default");
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        frame.getContentPane().add(textField_2, "13, 6, 3, 1, fill, default");
        textField_2.setColumns(10);

        JButton btnNewButton = new JButton("Selection");
        frame.getContentPane().add(btnNewButton, "4, 7");

        JButton btnNewButton_2 = new JButton("Selection");
        frame.getContentPane().add(btnNewButton_2, "9, 7");

        JButton btnNewButton_1 = new JButton("Selection");
        frame.getContentPane().add(btnNewButton_1, "14, 7");

        textField_3 = new JTextField();
        frame.getContentPane().add(textField_3, "3, 11, 9, 1, fill, default");
        textField_3.setColumns(10);

        btnSelection = new JButton("Selection");
        frame.getContentPane().add(btnSelection, "14, 11");

        btnCommencer = new JButton("Commencer");
        frame.getContentPane().add(btnCommencer, "9, 13");

        textField_4 = new JTextField();
        frame.getContentPane().add(textField_4, "6, 14, 7, 1, fill, default");
        textField_4.setColumns(10);

    }

}

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您必须摆弄秋千主题[1]。 WB预览使用与运行程序时使用的预览不同的预览。在运行时,可能未设置主题。

[1] Java eclipse WindowBuilder, change look and feel