Results 1 to 3 of 3
Thread: Layout manager
- 12-19-2011, 11:43 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 13
- Rep Power
- 0
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(); } } } }
- 12-19-2011, 05:15 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,145
- Rep Power
- 5
Re: Layout manager
See: A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
A SpringLayout or GridBagLayout should work.
- 12-19-2011, 07:23 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Layout Manager suggestion
By 0026sd in forum AWT / SwingReplies: 2Last Post: 09-19-2011, 05:54 PM -
Problem with layout manager
By mDennis10 in forum New To JavaReplies: 8Last Post: 09-05-2011, 03:02 AM -
Layout Manager
By globo in forum New To JavaReplies: 8Last Post: 11-01-2010, 12:19 AM -
Layout manager
By Nicholas Jordan in forum Java AppletsReplies: 2Last Post: 11-24-2008, 03:02 PM -
MiG Layout Manager 2.4
By levent in forum Java SoftwareReplies: 0Last Post: 05-16-2007, 05:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks