swing登陆见面怎么设置组件的大小随窗口的变化而变化

package com.model;
import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;
import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;
import com.nio.Client;
public class LoginUI { private JTextField tf; private JPasswordField pf; private JLabel lu,lp,li; private JButton b1; public LoginUI(){ JFrame f = new JFrame(); f.setLayout(new FlowLayout(FlowLayout.CENTER)); JPanel p = new JPanel(); f.getContentPane().setLayout(null); f.add(getUsername()); f.add(getTextField()); f.add(getPassword()); f.add(getJPasswordField()); f.add(getBLogin());// f.add(getImage()); f.setSize(500,350); f.setLocationRelativeTo(null); f.setVisible(true); f.setTitle("登陆界面"); f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); } /** * 文本输入框 * @return */ private JTextField getTextField(){ if(tf == null){ tf = new JTextField(); tf.setSize(320,20); } return tf; } /** * 密码输入框 * @return */ private JPasswordField getJPasswordField(){ if(pf == null){ pf = new JPasswordField(); pf.setSize(320, 20); } return pf; } /** * 有户名标签 * @return */ private JLabel getUsername(){ if(lu == null){ lu = new JLabel(); lu.setSize(80,25); lu.setText("用户名:"); } return lu; } /** * 密码标签 * @return */ private JLabel getPassword(){ if(lp == null){ lp = new JLabel(); lp.setText("密 码:"); lp.setSize(80,25); } return lp; } // private JLabel getImage(){// if(li == null){// li = new JLabel(new ImageIcon("img/wo.png"));// li.setBounds(55,66,80,100);//// li.setLocale(null);// }// return li;// } /** * 登陆按钮 * @return */ private JButton getBLogin(){ if(b1 == null){ b1 = new JButton(); b1.setText("登陆"); b1.setBounds(360,66,70,20); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { } }); } return b1; } /** * main方法测试效果 * @param args */ public static void main(String[] args) { new LoginUI(); }}

代码该怎么修改
双击窗口变大后,组件不会变大,看着很别扭,怎么让组件变大?要使用布局管理器吗,怎么使用,初学者求指教

首先 建议你这个登录界面 固定死 不让他随便改变大小
如果你想随着变化的话 我暂时知道的 只能监听你界面的大小 再自己定义组件的大小 再更新界面
布局管理器的话对你这样的要求满足不了的
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-04-04
可以使用BorderLayout试试
相似回答