Java jdialog框打开,但显示为空
我已经编写了以下代码,以便在生成决策树时生成please waitJava jdialog框打开,但显示为空,java,swing,jdialog,Java,Swing,Jdialog,我已经编写了以下代码,以便在生成决策树时生成please waitJDialog,但是它打开了,并且看起来是空的 public JDialog pleasewait() { JDialog dialog = new JDialog(); JLabel label = new JLabel("Please wait..."); label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/decision_
JDialog
,但是它打开了,并且看起来是空的
public JDialog pleasewait()
{
JDialog dialog = new JDialog();
JLabel label = new JLabel("Please wait...");
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/decision_tree_runner/load.gif"))); // NOI18N
dialog.setBackground(Color.BLACK);
dialog.setLocationRelativeTo(null);
dialog.setTitle("Please Wait...");
dialog.add(label);
dialog.pack();
return dialog;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JDialog dialog = pleasewait();
dialog.repaint();
dialog.setVisible(true);
FypProject fyp_project = new FypProject();
try {fyp_project.main_fypproject();} catch (SQLException ex) {}
dialog.setVisible(false);
}
我认为这与在对话框中添加JLabel的位置有关。由于缺乏我们的布局经理,这很难做到 在添加JLabel之前,请尝试添加以下内容:
dialog.setLayout(新的GridLayout())代码>
并删除:
dialog.pack()代码>可能是fyp\u project.main\u fyproject()
是一个长时间运行/阻塞调用,当从事件调度线程的上下文中调用时,它将停止处理新事件,包括重新绘制请求
考虑使用类似于SwingWorker
的方法,首先打开对话框,执行worker,当调用done
方法时,关闭对话框
查看并了解更多详细信息我执行了以下步骤
为它创建单独的表单
为fyp_项目创建了线程。main_fyp项目()
已将窗体的对象传递给线程类
在运行方法setvisible()时,请将选项改为false
public class thread_for_pleasewait implements Runnable{
Thread t ;
please_wait_form pwf;
decision_tree dt;
FypProject fyp_project = new FypProject();
@Override
public void run()
{
String[] args = null;
try {
fyp_project.main_fypproject();
pwf.setVisible(false);
dt.setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(thread_for_pleasewait.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void start(please_wait_form pwf,decision_tree dt)
{
t = new Thread(this);
t.start();
this.pwf=pwf;
this.dt=dt;
}
}
添加此选项会缩小对话框,但仍然没有显示任何内容如果从标签中删除图像会发生什么情况?用户489041仍然没有更改它们已经有一个布局管理器在使用中,因此更改它应该不会有任何效果…删除包是一个非常糟糕的主意