JTextField固定高度

unl*_*hed 7 java size swing jtextfield

JTextField当Frame最大化时,如何获得固定高度?我希望它看起来与Ubuntu上的Skype应用程序类似.

private JTextField username;
private JPasswordField password;
private JLabel usernamelabel;
private JLabel passwordlabel;
public LoginPanel(){


    setSize(200,200);
    setLayout(new GridLayout(4,4));
    setBackground(new Color(85,153,187));
    setBorder(BorderFactory.createEmptyBorder(70, 70, 70, 70));
    username = new JTextField();
    password = new JPasswordField();
    usernamelabel= new JLabel("Username");
    passwordlabel= new JLabel("Password");
    username.setBounds(5, 5, 100, 100);
    username.setPreferredSize(new Dimension(80,20));
    password.setPreferredSize(new Dimension(80,20));
    add(usernamelabel);
    add(username);
    add(passwordlabel);
    add(password);
Run Code Online (Sandbox Code Playgroud)

jzd*_*jzd 6

不要使用比其他的布局GridLayout或将文本字段中具有另一面板FlowLayout,你里面坐GridLayout.