Results 1 to 5 of 5
  1. #1
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default 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);
    Can someone tell me what am I doing wrong...

    Thanks in advance...

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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);
    ?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Or else you should use a container to add components. Set the container layout into SpringLayout.

  4. #4
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    Thanks guys. As Fubarable pointed, I wasn't "add"ing my controls to the panel. :)...

    it works now, thanks guys.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Text-pain
    By willemjav in forum Java Applets
    Replies: 5
    Last Post: 06-21-2008, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •