Results 1 to 3 of 3
  1. #1
    rahul405804 is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default How to add components line by line?

    I want to add components in JPanel line by line.
    I have tried several layouts including GridLayout, GridBagLayout and BorderLayout. But 'new line' arrangement of components is not happening..

    Here is my code:

    Java Code:
    class Login extends JFrame implements ActionListener
    {
        JButton login,register;
        JPanel  panel;
        JLabel label1,label2;
        public JTextField  text1,text2;
        RegisterAction regAction = null;
        
     
         
         public Login()
         {
    		 
            	label1 = new JLabel();
            	regAction = new RegisterAction();
            	
                label1.setText("Username:");
                text1 = new JTextField(15);
    
                label2 = new JLabel();
                label2.setText("Password:");
                text2 = new JPasswordField(15);
         
                login=new JButton("Login");
                register = new JButton("Register");
           
                panel=new JPanel(new GridBagLayout());
                panel.add(label1);
                panel.add(text1);
                panel.add(label2);
                panel.add(text2);
                panel.add(login);
                panel.add(register);
                add(panel,BorderLayout.CENTER);
                login.addActionListener(this);
                register.addActionListener(regAction);
                setTitle("File Jamming Synthesizer");
                      
    }

    This one is of JFrame, I have tried out Jpanel too..In both cases anot working..

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

    Default Re: How to add components line by line?

    Look up the BoxLayout, but you'll want to read the whole tutorial and API on it as it has some tricky parts. For that matter, you'll want to read the whole layout manager tutorial as well.

  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

Similar Threads

  1. Replies: 16
    Last Post: 09-17-2011, 03:41 AM
  2. Replies: 1
    Last Post: 02-13-2011, 04:09 PM
  3. tracing java application line by line using netbeans
    By chandrasekhar123 in forum NetBeans
    Replies: 1
    Last Post: 08-03-2010, 03:46 PM
  4. Replies: 2
    Last Post: 07-02-2010, 03:20 PM
  5. Replies: 4
    Last Post: 09-10-2009, 11:18 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
  •