Cod*_*gel 8 java swing jframe netbeans-7
我正在使用NetBeans开发一个java swing桌面应用程序,我想将JFrame设置为屏幕的中心.
从网上我明白我可以使用
setLocationRelativeTo(null);
Run Code Online (Sandbox Code Playgroud)
将框架设置为中心但是我无法将代码插入NetBeans IDE,因为NetBeans 7 IDE的生成代码frame.pack()
和frame.setVisible()
生成的代码都不允许在两种方法之间插入任何代码.
我需要获得以下内容:
frame.pack()
setLocationRelativeTo(null);
frame.setVisible()
Run Code Online (Sandbox Code Playgroud)
有关如何解决问题的任何建议?
小智 13
在框架的构造函数,你有这个:
public frame() {
initComponents();
}
Run Code Online (Sandbox Code Playgroud)
你只需要输入这一行:"this.setLocationRelativeTo(null);" 在"initComponents();"下
你会有这个:
public frame() {
initComponents();
this.setLocationRelativeTo(null);
}
Run Code Online (Sandbox Code Playgroud)
运行它,框架应显示在屏幕的中心=)
是setVisible()
在生成的代码上吗?奇怪的。无论如何,您可以右键单击JFrame
并Navigator
选择Properties
。转至Code
并选择它以不执行任何操作。initComponents()
然后在构造函数中手动插入代码JFrame
。
归档时间: |
|
查看次数: |
68312 次 |
最近记录: |