【发布时间】:2014-12-27 13:48:55
【问题描述】:
当我运行 JFrame 时,它会以隐藏大小显示我。我必须调整大小才能看到 JFrame。
为什么我无法获得完整大小的JFrame。
我用过:Pack(); setVisible(true);,但它不起作用。
这是我的代码:
public class Mytest extends JFrame{
JLabel label=new JLabel();
JLabel label2=new JLabel();
Timer myTimer;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Mytest().show();
}
public Mytest(){
getContentPane().setLayout(new GridBagLayout());
setTitle("test");
GridBagConstraints gridCon=new GridBagConstraints();
gridCon.gridx=0;
gridCon.gridy=0;
getContentPane().add(label,gridCon);
gridCon.gridx=0;
gridCon.gridy=1;
getContentPane().add(label2,gridCon);
myTimer = new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e){
myTimerActionPerformed(e);
}
});
pack();
myTimer.start();
setLocationRelativeTo(null);
}
private void myTimerActionPerformed(ActionEvent e){
Date today=new Date();
label.setText(DateFormat.getDateInstance(DateFormat.FULL).format(today));
label2.setText(DateFormat.getTimeInstance().format(today));
}
}
【问题讨论】:
标签: java swing netbeans jframe