Results 1 to 3 of 3

Thread: Layout manager

  1. #1
    dacoolest is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Layout manager

    I want to create a gui window which should looks like a login page of a website.
    in the first row, a JLabel and a JTextField should be there to enter the username.
    in the second row, another JLabel and a JPasswordField should be placed to enter the password.
    in the third row, a login button should be placed.

    I created the gui but having problems with setting up the layout manager. Please help me to get it corrected. Thanks.

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class loginGui {
    
    	private JFrame frame;
    	private JPanel jp;
    	private JTextField userName;
    	private JPasswordField pass;
    	private JButton login;
    	private sessionManager sManager;
    	private List list;
    	
    	public loginGui(sessionManager s){
    		sManager = s;
    		frame = new JFrame("Login");
    		
    		
    		
    		jp = new JPanel(new GridLayout(3, 1, 10, 50));
    		
    		userName = new JTextField("myname");
    		pass = new JPasswordField("mypass");
    		login = new JButton("Login");
    		login.addActionListener(new myActionListener() );
    		
    		frame.setContentPane(jp);
    	//	jp.setLayout(new GridLayout(3,1));
    		jp.add(userName);
    		jp.add(pass);
    		jp.add(login);
    		
    		frame.setSize(400,400);
    		frame.setVisible(true);
    	}
    	
    	private class myActionListener implements ActionListener{
    		public void actionPerformed(ActionEvent e){
    			
    			String n = userName.getText();
    			String p = pass.getText();
    
    			User u = new User();
    			u = sManager.list.validate(n, p);
    			if(u == null){
    				System.out.println("Invalid login");
    			}
    			else {
    				System.out.println("Valid login");
    				sManager.currentUser = u;
    				sManager.configure();
    			}
    			
    		}
    	}
    	
    	
    	
    	
    }

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

  3. #3
    dacoolest is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Layout manager

    Thanks. I got it properly set up with GridBagLayout.

Similar Threads

  1. Layout Manager suggestion
    By 0026sd in forum AWT / Swing
    Replies: 2
    Last Post: 09-19-2011, 06:54 PM
  2. Problem with layout manager
    By mDennis10 in forum New To Java
    Replies: 8
    Last Post: 09-05-2011, 04:02 AM
  3. Layout Manager
    By globo in forum New To Java
    Replies: 8
    Last Post: 11-01-2010, 01:19 AM
  4. Layout manager
    By Nicholas Jordan in forum Java Applets
    Replies: 2
    Last Post: 11-24-2008, 04:02 PM
  5. MiG Layout Manager 2.4
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-16-2007, 06:11 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
  •