[SOLVED] JFrame Layout
Hi, I just started using swing with JFrames and the like. In teaching myself, I wanted to make a simple username/password verification application. Unfortunately, when I try to set up the layout (not using GridLayout) the buttonResize button I add is taking up the entire frame. I tried adding buttonSubmit after buttonResize, and the same problem happened with buttonSubmit.
JButton buttonResize = new JButton("Resize");
ActionListener actionListener2 = new ActionListener()
public void actionPerformed(ActionEvent actionEvent)
EDIT: Sorry, I just realized there was a section for awt/swing ... Next time I'll remember. ;)
usernameLabel.setBounds(0, 0, 96, 16);
passLabel.setBounds(0, 16, 96, 16);
username.setBounds(96, 0, 96, 16);
pass.setBounds(96, 16, 96, 16);
buttonSubmit.setBounds(0, 32, 96, 16);
buttonResize.setBounds(96, 32, 96, 16);
Which LayoutManager are you using? If you're not using one at all you have to manually deal with the bounds of every component.
You're also going to need to call revalidate() and/or repaint() after changing the size of the frame.
I'm setting all of the bounds manually, just as practice. I used GridLayout and it worked fine, however when I try using setBounds with everything for some reason buttonResize takes up the entire frame. I do use "buttonResize.setBounds(96, 32, 96, 16);" I tried adding buttonSubmit after buttonResize, and the same problem happened with buttonSubmit, and buttonResize was in the right place. So this problem happens with the last thing I add to frame. Here's a picture:
Yes, but to confirm: which layout manager are you using? Do you setLayout(null) at some point?
Originally Posted by AndrewM16921
Ahh, that's the problem. Thanks. :)