Reputation: 60026
I try to set two JTextField
side by side, I use Netbeans, this is what I already do :
I can't arrive to set them 50% 50%, and when I maximize my frame this what happen:
Is there any way to solve this problem?
Thank you.
Upvotes: 0
Views: 449
Reputation: 1210
You should use GridBag Layout. Then open the layout editing (right click the layout) and give all text areas a width of 1.0 and fill of "both".
Upvotes: 2
Reputation: 3960
Is your problem that only the one textField changes is width?? If yes you can use a GroupLayout like this:
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);
Upvotes: 2