I am doing the 1st screen of my app and here is what I want to do. I have a JFrame that contains a small JPanel. The JPanel needs to be center of the screen.
The Panel consist of a JLabel, JTextField and JButton from top to bottom. When I add the panel to the frame, everything is perfect. However, I need to add a "CLOSE" button on the lower right hand corner of the screen. As soon as I add the button, the JPanel appear to be pushed to the left. Is there a way to add the close button without my JPanel get pushed to the left, please help.
Remember to reset the:
constraints.weighty = 0.0;
for the button.
Setting a negative inset is bad practice. You are setting 200 for the right for the panel and then -300 for the button. Instead, just set +100 for the panel and nothing for the button.