Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes JPanel and JTextfield not aligning correctly.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JPanel and JTextfield not aligning correctly.." Watch "JPanel and JTextfield not aligning correctly.." New topic
Author

JPanel and JTextfield not aligning correctly..

Michael Raymond Jr.
Ranch Hand

Joined: May 16, 2005
Posts: 178
Below is part of the code i'm trying to get working...well, it works and compiles, but I can't get it to display how I want it to.

Basically, it's a rectangular box with two jlabels and 2 Jtextfields like so:

File Name: [ ]
Folder name: [ ]

Above is how I want it to appear, but instead it's appearing like:

File Name: [ ] Folder name:
[ ]

Total dorkyness....there's probably a layout mnger, but I can't find a way to fix this. Any help would be great!



{code}:

JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(500, 200));

//for first row of frame
JLabel searchtext = new JLabel("File Name:", SwingConstants.LEFT);
JTextField searchfiles = new JTextField (20);

panel.add(searchtext);
panel.add(searchfiles);


//second row of frame
JLabel foldername = new JLabel("Folder Name:", SwingConstants.LEFT);
JTextField createfolder = new JTextField (20);

panel.add(foldername);
panel.add(createfolder);

{code end}


Scooby Snacks for everyone...<br /> <br />SCJA, SCJP 1.4
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
see if this does what you want

Michael Raymond Jr.
Ranch Hand

Joined: May 16, 2005
Posts: 178
cool dude...

i plugged in the layout manager (right?) 'gridlayout' and it worked...however, I had to remove:

"panel.setPreferredSize(new Dimension(500, 200));"

that(above) was screwing everything up.

another question...

Where on Java's API list can I find these layout managers for swing???
I'm pretty sure they are not listed under javax.swing.*
http://java.sun.com/j2se/1.5.0/docs/api/

Thanks!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this might be a better link for you

http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JPanel and JTextfield not aligning correctly..
 
Similar Threads
Navigating between two JFrame in Java Swing
FlowLayout Display Problems
Dynamic tables
Multiple controls in a panel
how to set this a borderq