0

I am new to gui in java, i spent 3 hours trying to figure out what i have done wrong or misunderstood, i should get this:

enter image description here

but the text in my code is displayed after textfields

   textPanel = new JPanel();
     textPanel.setLayout(new GridLayout(3,0)); 

     fName = new JTextField( 15 ) ; 
     textPanel.add(fName);
     jlbName = new JLabel ( "Firstname" );
    jlbName.setHorizontalAlignment(JLabel.RIGHT);
    textPanel.add(jlbName);

     lName = new JTextField( 15 ) ; 
    textPanel.add(lName);
    jlbName = new JLabel ( "LastName" );

    jlbName.setHorizontalAlignment(JLabel.RIGHT);
    textPanel.add(jlbName);



    libNo = new JTextField( 15 ) ; 
    textPanel.add(libNo);
       libNo.setEditable(false);
    jlbName = new JLabel ( "Library Number" );

    jlbName.setHorizontalAlignment(JLabel.RIGHT);
    textPanel.add(jlbName);


   add(textPanel,BorderLayout.EAST);
   JButton jbtN = new JButton("Add borrower");
   add(jbtN ,BorderLayout.SOUTH);
1
  • can you be more specific? Commented Apr 1, 2014 at 6:07

1 Answer 1

3

You are inserting the components into the panel in the wrong order. You first insert the text fields and later the labels. Do the opposite, i.e. instead of:

textPanel.add(fName);
...
textPanel.add(jlbName);
...

do:

textPanel.add(jlbName);
...
textPanel.add(fName);
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.