可能重复:
JDialog 停止父 JFrame 的执行
我必须 JFrame 并且它没有装饰并且只有一个进度条的图像......但是当我想向服务器发送请求时我希望它显示进度条并且它没有显示它但是我的窗口已加载....我已经尝试过 jDialog 但它正在停止执行我的代码..
这是我的代码
private void LoginBtnActionPerformed(java.awt.event.ActionEvent evt) {
ProgressBar pb = new ProgressBar();
pb.setVisible(true);
List<BasicNameValuePair> postPairs = new ArrayList<BasicNameValuePair>();
AsyncService asyncService = new AsyncService();
postPairs.add(new BasicNameValuePair("PATH","authenticateUser.idoc"));
postPairs.add(new BasicNameValuePair("user_email",email));
postPairs.add(new BasicNameValuePair("user_password",password));
JSONArray jArray = asyncService.sendRequest(postPairs);
pb.setVisible(true);
}
除了 gif 动画图像和标签之外,我的进度条框架中没有任何内容... EDIT 1 */
class WorkerProgressBar extends SwingWorker<Integer, Integer>
{
private JFrame pb = new JFrame();
JDialog dialog = new JDialog();
JPanel panel = new JPanel();
JLabel label = new JLabel();
public WorkerProgressBar(){
panel = new JPanel();
panel.setBackground(new Color(114,114,114));
JLabel imageLabel = new JLabel(new ImageIcon(getClass().getResource("/icons/progress_bar.gif")));
imageLabel.setBorder(BorderFactory.createLineBorder(Color.black));
panel.add(imageLabel);
dialog.getContentPane().add(panel,BorderLayout.CENTER);
dialog.pack();
dialog.setLocationRelativeTo(null);
}
protected Integer doInBackground() throws Exception
{
dialog.setVisible(true);
return 0;
}
protected void done()
{
try
{
dialog.setVisible(false);
}
catch (Exception e)
{
e.printStackTrace();
}
}