当用户单击我的应用程序中的特定按钮时,我试图在新的 JFrame 中显示正在加载的图像。显示了 JFrame,但它什么也没显示!,背景也是白色的,而所有 JFrame 都是灰色的默认背景。这里有什么问题?
stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
analyzer.running=false;
JFrame Load1=new JFrame("Load1");
ImageIcon icon1=new ImageIcon("./ajax-loader.gif");
System.out.println(icon1.getIconHeight());
Load1.add(new JLabel("Retrieving...", icon1, JLabel.CENTER),BorderLayout.CENTER);
Load1.pack();
Load1.setSize(400,400);
Load1.setVisible(true);
System.out.println("Start Processing");
parser.parse(); // Time Consuming method
nw_Creator.create();
System.out.println("End Processing");
Load1.setVisible(false);
home.setVisible(false);
screen2.setVisible(true);
}
});
最佳答案
不要将耗时的部分放在事件处理程序中或在事件分发线程中运行的任何方法中。您可能想使用 swing worker相反。
关于java - Jframe 内容不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9930830/