并排设置两个 JTextArea netbeans

Set two JTextArea side by side netbeans

我尝试并排设置两个 JTextField,我使用 Netbeans,这是我已经在做的事情:

我无法到达设置它们 50% 50%,当我最大化我的框架时,会发生以下情况:

有什么办法可以解决这个问题吗?

谢谢。

你的问题是只有一个textField改变了宽度吗??如果是,您可以像这样使用 GroupLayout:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);

JTextField textField = new JTextField();
textField.setColumns(10);

JTextField textField_1 = new JTextField();
textField_1.setColumns(10);
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
        gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_contentPane.createSequentialGroup()
                .addComponent(textField, GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
    );
gl_contentPane.setVerticalGroup(
        gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_contentPane.createSequentialGroup()
                .addContainerGap()
                .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
                    .addComponent(textField_1, Alignment.LEADING)
                    .addComponent(textField, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
                .addContainerGap(159, Short.MAX_VALUE))
    );
contentPane.setLayout(gl_contentPane);

您应该使用 GridBag 布局。然后打开布局编辑(右键单击布局)并为所有文本区域设置宽度 1.0 和填充 "both".