Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel and JTextfield not aligning correctly..

 
Michael Raymond Jr.
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see if this does what you want

 
Michael Raymond Jr.
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this might be a better link for you

http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic