Results 1 to 5 of 5
Thread: SpringLayout ... Pain!
- 11-09-2008, 07:49 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
SpringLayout ... Pain!
Hi all,
I have a Panel, and have 2 JLabel and 2 JTextFeild on it. Which is for userID and password. I just want tot display in the first row UserID (JLabel) and to the right I want display the JTextFeild for UserID.
then on the second row(beneath the JLabel for UserID) I want to display the JLabel for Password: and to the right the JPasswordFeild for it. Here's what I am trying, but when I run the program, I only see one lable and one textfeild for user name only. I think the password label/textfeild is displayed under them. Here's the code:
Java Code:JPanel pane = new JPanel (); SpringLayout sp = new SpringLayout(); pane.setLayout(sp); pane.add(lblUserName); pane.add(txtUserName); sp.putConstraint(SpringLayout.WEST, lblUserName, 5, SpringLayout.WEST, this); sp.putConstraint(SpringLayout.NORTH, lblUserName, 5, SpringLayout.NORTH, this); sp.putConstraint(SpringLayout.WEST, txtUserName, 5, SpringLayout.EAST, lblUserName); sp.putConstraint(SpringLayout.NORTH, txtUserName, 5, SpringLayout.NORTH, this); sp.putConstraint(SpringLayout.WEST, lblPassword, 5, SpringLayout.WEST, this); sp.putConstraint(SpringLayout.NORTH, lblPassword, 5, SpringLayout.SOUTH, lblUserName); sp.putConstraint(SpringLayout.WEST, txtPassword, 5, SpringLayout.EAST, lblPassword); sp.putConstraint(SpringLayout.NORTH, txtPassword, 5, SpringLayout.SOUTH, txtUserName);
Thanks in advance...
-
I don't know SpringLayout, but I do know that you won't see anything if you don't add it to the JPanel. Where are you adding the password's label and jtextfield to your "pane" JPanel?
In other words, where do you have:
Java Code:pane.add(lblPassword); pane.add(txtPassword);
- 11-10-2008, 10:44 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Or else you should use a container to add components. Set the container layout into SpringLayout.
- 11-10-2008, 04:59 PM #4
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
Thanks guys. As Fubarable pointed, I wasn't "add"ing my controls to the panel. :)...
it works now, thanks guys.
- 11-10-2008, 05:59 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Fine. If you have solve the question please mark it as solved form the Tread Tools menu.
Similar Threads
-
Text-pain
By willemjav in forum Java AppletsReplies: 5Last Post: 06-21-2008, 11:01 AM
Bookmarks