这个问题是重复的,但其他答案没有修复这个错误。我放入 JFrame 中的组件没有显示。我已经使用 JFrame 一段时间了,据我所知,我没有犯任何错误。
我的代码:
public void Toutrial_start1()
{
Container contentPane = new Container();
setSize(800,500);
setLocation(100,100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Wizard101");
setResizable(false);
tou1 = new JLabel();
tou1.setBounds(0,0, 800, 500);
tou1.setIcon(t1);
but = new JButton();
but.setBounds(100,100, 200, 200);
but.addActionListener(this);
but.setIcon(t1);
contentPane.add(but);
contentPane.add(tou1);
setVisible(true);
SchoolDecider();
genderDecider();
nameDecider();
playerStats.Stats();
}
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
}
}
最佳答案
您尚未向框架添加内容。您已创建 contentPane
但尚未将其添加到 jframe 。请在调用 setVisible()
之前添加它
this.setContentPane(contentPane);
setVisible(true);
关于java - 组件不会显示在 JFrame 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30739010/