| | |
JFrame & SpringLayout problem.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 126
Reputation:
Solved Threads: 6
Hi all,
I have a simple JFrame windows with two JLabel, two JTextField and two JButton. I use SpringLayout to display controls in on the frame. But when I run the application, the windows is displayed in a very small size. Only the two buttons are displayed. But when I maximize the window all the controls are placed properly.
So, I think, the setSize() is not functioning properly. Can someone please tell me what i am doing wrong? Appreciate your help. Here's the code for this:
Thanks in advance...
I have a simple JFrame windows with two JLabel, two JTextField and two JButton. I use SpringLayout to display controls in on the frame. But when I run the application, the windows is displayed in a very small size. Only the two buttons are displayed. But when I maximize the window all the controls are placed properly.
So, I think, the setSize() is not functioning properly. Can someone please tell me what i am doing wrong? Appreciate your help. Here's the code for this:
java Syntax (Toggle Plain Text)
public class Login extends JFrame implements ActionListener { public Login () { super("Title"); this.getContentPane().setLayout(new BorderLayout()); JPanel btnPane = new JPanel(); btnPane.setLayout(new FlowLayout()); JPanel pane = new JPanel(); SpringLayout sp = new SpringLayout(); pane.setLayout(sp); pane.add(lblUserName); pane.add(txtUserName); pane.add(lblPassword); pane.add(txtPassword); sp.putConstraint(SpringLayout.WEST, lblUserName, 70, SpringLayout.WEST, this); sp.putConstraint(SpringLayout.NORTH, lblUserName, 20, SpringLayout.NORTH, this); sp.putConstraint(SpringLayout.WEST, txtUserName, 5, SpringLayout.EAST, lblUserName); sp.putConstraint(SpringLayout.NORTH, txtUserName, 20, SpringLayout.NORTH, this); sp.putConstraint(SpringLayout.WEST, lblPassword, 70, 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); btnLogin.addActionListener(this); btnCancel.addActionListener(this); btnPane.add(btnLogin); btnPane.add(btnCancel); this.getContentPane().add("Center", pane); this.getContentPane().add("South",btnPane); } public static void main (String[] args) { Login login = new Login(); login.setSize(10, 20); login.setLocation(200,200); login.pack(); login.setVisible(true); } public void actionPerformed(ActionEvent e) { // do some actions } private JLabel lblUserName = new JLabel("User name: "); private JTextField txtUserName = new JTextField(15); private JLabel lblPassword = new JLabel("Password : "); private JPasswordField txtPassword = new JPasswordField(15); private JButton btnLogin = new JButton("Login"); private JButton btnCancel = new JButton("Cancel"); }
Thanks in advance...
![]() |
Other Threads in the Java Forum
- Previous Thread: 2d array problem
- Next Thread: 2d arrayist
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes clear client code component consumer database draw eclipse ee error event exception fractal free game gameprogramming gis givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javaprojects jni jpanel julia jvm key linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline nls notdisplaying number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






