Results 1 to 5 of 5
Thread: [SOLVED] JFrame Layout
- 04-09-2009, 12:30 AM #1
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
[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.
Java Code:JButton buttonResize = new JButton("Resize"); ActionListener actionListener2 = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { frame.setSize(200, 100); } }; buttonResize.addActionListener(actionListener2); frame.add(buttonResize);EDIT: Sorry, I just realized there was a section for awt/swing ... Next time I'll remember. ;)Java Code: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);
Last edited by AndrewM16921; 04-09-2009 at 12:47 AM.
- 04-09-2009, 12:36 AM #2
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.Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 04-09-2009, 12:44 AM #3
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
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:
Last edited by AndrewM16921; 04-09-2009 at 12:48 AM.
- 04-09-2009, 01:00 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
- 04-09-2009, 01:11 AM #5
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Similar Threads
-
Layout manager
By Nicholas Jordan in forum Java AppletsReplies: 2Last Post: 11-24-2008, 03:02 PM -
Border Layout
By mark-mlt in forum Java AppletsReplies: 5Last Post: 05-12-2008, 09:48 AM -
Help with JButton and layout
By adlb1300 in forum AWT / SwingReplies: 1Last Post: 12-25-2007, 08:33 AM -
Layout Managers
By gmioannou in forum AWT / SwingReplies: 1Last Post: 12-24-2007, 04:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks