我知道没有办法制作JProgressMonitor
模态框,人们宁愿将 aJDialog
与 a 一起使用JProgressBar
。现在,我得到了这个工作 - 但只要我不试图制作JDialog
模态。谁能告诉我我做错了什么?
private Frame frame;
private JPanel contentPane;
private JProgressBar progressBar;
public MainClass() {
JButton startBtn = new JButton("Start");
startBtn.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent arg0)
{
new Thread(new Runnable()
{
@Override
public void run()
{
createJDialog();
for (int i = 0; i < 100; ++i)
{
final int j = i;
doInBackground(); // Batch process
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
progressBar.setValue(j);
}
});
}
}
}).start();
}
});
}
public void createJDialog()
{
JDialog d = new JDialog();
d.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// Keeps progressBar from updating
// d.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
// d.setModal(true);
d.getContentPane().add(progressBar, BorderLayout.PAGE_START);
d.getContentPane().add(progressBar, BorderLayout.PAGE_END);
d.pack();
d.setVisible(true);
}