gpt4 book ai didi

Java Swing GUI - 界面困惑 - 字段未显示

转载 作者:行者123 更新时间:2023-12-01 19:37:30 25 4
gpt4 key购买 nike

电子邮件字段覆盖在姓名字段上...并且按钮未显示。

enter image description here

我正在尝试制作一个简单的注册屏幕。

package javainterfacegrafica;

import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JavaInterfaceGrafica extends JFrame {

private void TelaJava(){
Container janela = getContentPane();
setLayout(null);

//Definindo os rótulos
JLabel labelUsername = new JLabel("Username: ");
JLabel labelPassword = new JLabel("Password: ");
JLabel labelConfirmPassword = new JLabel("Confirm Pass.: ");
JLabel labelName = new JLabel("Name: ");
JLabel labelEmail = new JLabel("Email: ");
labelUsername.setBounds(50,40,100,20);
labelPassword.setBounds(50,80,100,20);
labelConfirmPassword.setBounds(50,120,120,20);
labelName.setBounds(50,160,100,20);
labelEmail.setBounds(50,160,100,20);

JFormattedTextField jFormattedTextUsername = new JFormattedTextField();
JFormattedTextField jFormattedTextPassword = new JFormattedTextField();
JFormattedTextField jFormattedTextConfirmPassword = new JFormattedTextField();
JFormattedTextField jFormattedTextName = new JFormattedTextField();
JFormattedTextField jFormattedTextEmail = new JFormattedTextField();
jFormattedTextUsername.setBounds(150,40,100,20);
jFormattedTextPassword.setBounds(150,80,100,20);
jFormattedTextConfirmPassword.setBounds(150,120,100,20);
jFormattedTextName.setBounds(150,160,180,20);
jFormattedTextEmail.setBounds(150,160,180,20);


//Botão
JButton btn = new JButton("Salvar");


//Adiciona os rótulos e os campos de textos com máscaras na tela
janela.add(labelUsername);
janela.add(labelPassword);
janela.add(labelConfirmPassword);
janela.add(labelName);
janela.add(labelEmail);
janela.add(jFormattedTextUsername);
janela.add(jFormattedTextPassword);
janela.add(jFormattedTextConfirmPassword);
janela.add(jFormattedTextName);
janela.add(jFormattedTextEmail);
janela.add(btn);

setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);

}


public static void main(String[] args) {

JavaInterfaceGrafica jig = new JavaInterfaceGrafica();``
jig.TelaJava();

}
}

最佳答案

由于以下 labelName.setBounds(50,160,100,20);,您的电子邮件布局被覆盖;
labelEmail.setBounds(50,160,100,20);
你基本上给了它们在框架上相同的位置。对于您的按钮,请尝试使用 setBounds(x, x, x, x); 为其在布局中指定一个位置。另外,对于像您这样的简单登录布局,我建议使用 2 列 5 行的 GridLayout(第五个用于您的登录按钮)。

关于Java Swing GUI - 界面困惑 - 字段未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56915319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com