JTextField固定高度

JTextField固定高度

本文介绍了JTextField固定高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当框架最大化时,如何使JTextField具有固定的高度?我希望它看起来类似于Ubuntu上的Skype应用程序.

How do I get the JTextField to have a fixed height when the Frame is maximized? I want it to look sort of similar to the Skype application on Ubuntu.

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);

推荐答案

请勿使用GridLayout以外的布局,也不要将文本字段放在具有FlowLayout且位于GridLayout内部的其他面板中

Don't use a layout other than GridLayout or put the text field in another panel that has a FlowLayout that sits inside of your GridLayout.

这篇关于JTextField固定高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:10