本文介绍了JButton没有出现在JFrame上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是jbutton未显示在框架上的代码.我也将visible设置为true.即使那样,按钮也不会出现.
Following is the code in which the jbutton is not showing on the frame. I have also set visible to true. Even then the button doesn't appear.
class gui{
public static void main(String args[]){
layoutBorder lb=new layoutBorder("check");
}
}
class layoutBorder extends JFrame{
layoutBorder(String title){
super(title);
setLayout(null);
setSize(200, 200);
JButton jb=new JButton("JB");
add(jb);
setVisible(true);
}
}
推荐答案
如果要使用null
布局,则需要自己设置尺寸和位置.使用setLocation
和setSize
方法.
If you want null
layouts then you need to set sizes and position by yourself. Using the setLocation
and setSize
methods.
class gui{
public static void main(String args[]){
layoutBorder lb=new layoutBorder("check");
}
}
class layoutBorder extends JFrame{
layoutBorder(String title){
super(title);
setLayout(null);
setSize(200, 200);
JButton jb=new JButton("JB");
jb.setLocation(10, 10);
jb.setSize(40, 30);
add(jb);
setVisible(true);
}
}
这篇关于JButton没有出现在JFrame上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!