本文介绍了为什么我的项目没有出现在JFrame的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是相当新的JFrame的,我想知道为什么我的项目没有显示在窗口中了。我知道我没有一个的ActionHandler,但我只是希望我的文本框的出现在我的窗口上。这里是我的code:
进口java.awt.Font中;
进口javax.swing.JFrame中;
进口javax.swing.JLabel中;
进口javax.swing.JPasswordField中;
进口javax.swing.JTextField中;公共类FirstGUI扩展的JFrame {
公共无效GUI(){
的setTitle(欢迎);
的setResizable(假);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
调用setVisible(真);
的setSize(600600); JLabel的标题=新的JLabel();
title.setText(苹果公司会员登录端口);
title.setFont(新字体(宋体,Font.PLAIN,24)); JTextField的登录名=新的JTextField(登录,10); JPasswordField中通=新JPasswordField(密码); 添加标题);
加(登录);
加(PASS); } 公共静态无效的主要(字串[] args){
FirstGUI一个=新FirstGUI();
a.GUI();
}
}
但是当我运行它,我得到这样的:
解决方案
You get an empty screen because you add the components to the frame after the frame is visible.
- As has already been suggested you need to use an appropriate layout manager. FlowLayout is the easiest to start with.
- invoke
setVisible(true)
AFTER adding the components to the frame.
So the code should be more like:
panel.add(...);
panel.add(...);
add(panel);
pack();
setVisible(true);
这篇关于为什么我的项目没有出现在JFrame的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!