[英]Progress bar with indeterminate mode on a button click doesn't work
我正在使用netbeans,这是按钮单击功能。 我希望进度条在单击按钮后立即运行。 该模式是不确定的,因为我正在调用类WriteToFile
并且它将在后台运行数分钟,并且不返回任何值。
private void createFileButtonActionPerformed(java.awt.event.ActionEvent evt)
{
String str = (String) selectTypeComboBox.getSelectedItem();
createFileButton.setEnabled(false);// Prevent more button presses
String filepaths = fileChooserWindow.getSelectedFile().getAbsolutePath();
String selectType =(String) selectTypeComboBox.getSelectedItem();
WriteToFile writeOBJ;
writeOBJ = new WriteToFile(filepaths,start,selectType);
try
{
writeOBJ.selectType();
}
catch (SQLException | IOException | RuntimeException ex)
{
System.exit(0);
}
}
得到这个工作:
jProgressBar1.setVisible(true);
jProgressBar1.setIndeterminate(true);
Executor executor = java.util.concurrent.Executors.newSingleThreadExecutor();
executor.execute(new Runnable(){
@Override
public void run(){
String str = (String) selectTypeComboBox.getSelectedItem();
createFileButton.setEnabled(false);// Prevent more button presses
String filepaths = fileChooserWindow.getSelectedFile().getAbsolutePath();
String selectType =(String) selectTypeComboBox.getSelectedItem();
WriteToFile writeOBJ;
writeOBJ = new WriteToFile(filepaths,start,selectType);
try
{
writeOBJ.selectType();
}
catch (SQLException | IOException | RuntimeException ex)
{
System.exit(0);
}
jProgressBar1.setVisible(false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.