Java Swing GUI控件在后台执行和操作时停止
现在,当我点击导入按钮时,一个操作在后端执行。因此,当GUI停止控制,我不能按下任何按钮,但我希望可以按下取消按钮,以便用户可以取消正在进行的操作。 我需要一些关于如何做的想法
JButton importButton = new JButton("Import");
importButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for(ResourceListObject currentImage : imagesToBeImported){
String ImOid = String.valueOf(currentImage.getOID());
String image_content = restEngine.getimageContent(ImOid);
String str[]=new String[3];
str[0] = "aix";
str[1] = image_content;
str[2] = selectedRepository.concat("_").concat(currentImage.getName());
PowerVC_Image_Deployer imgDeployer= new PowerVC_Image_Deployer(str);
}
}
# 1 楼答案
您的问题是GUI正在调用操作并阻塞,也就是说,它等待操作完成,因为它正在等待,所以不能进行用户交互。要解决这个问题,必须在应用程序中使用多个线程
你可以在这里找到更多信息:http://docs.oracle.com/javase/tutorial/uiswing/concurrency/