SpringLayout ... Pain!
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:
Can someone tell me what am I doing wrong...
JPanel pane = new JPanel ();
SpringLayout sp = new SpringLayout();
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:
Or else you should use a container to add components. Set the container layout into SpringLayout.
Thanks guys. As Fubarable pointed, I wasn't "add"ing my controls to the panel. :)...
it works now, thanks guys.
Fine. If you have solve the question please mark it as solved form the Tread Tools menu.