JFrame居中显示问题
Pol 2007-11-17 10:38:03 我在网上找的JFrame居中代码,
setLocationRelativeTo(null);
或
Toolkit kit = Toolkit.getDefaultToolkit():
Dimension screenSize = kit.getScreenSize();
f.setLocation((screenSize.width-f.getWidth())/2, (screenSize.height-f.getHeight())/2);
或为:
this.setLocation(this.getToolkit().getScreenSize().width/2-this.getWidth()/2,this.getToolkit().getScreenSize().height/2-this.getHeight()/2);
但是我用的时,怎么是在右下方显示的了?我换了几个程序都是这样了.
这是怎么回事?
我的一个程序代码如下:
public class FunctionChoice extends JFrame {
JPanel contentPane;
ButtonGroup buttonGroup1 = new ButtonGroup();
..........
JTextPane jTextPane1 = new JTextPane();
public FunctionChoice() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);//居中显示
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
......