【发布时间】:2015-12-24 03:45:56
【问题描述】:
我的应用程序是使用 Netbeans IDE (8.0.2) 创建的。 我创建了一个 JFrame,其中包含一个绑定到数据库的 JTable(使用 JPA)。
我添加了一个“刷新”按钮,用于直接从数据库中“刷新”JTable 数据。
我希望在获取数据时显示“请稍候”消息。
为此,我实现了一个扩展 JDialog 的 JDialog_PleaseWait 类。
出于某种奇怪的原因,虽然显示了 JDialog,但它包含的 jLabel 没有显示...
JDialog_PleaseWait 类是:
public class JDialog_PleaseWait extends javax.swing.JDialog {
//constructor for PleaseWait jDialogs
public JDialog_PleaseWait(String messageToDisplay){
initComponents();
this.jLabel_WaitMessage.setText(messageToDisplay);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel_WaitMessage = new javax.swing.JLabel();
setTitle("Please wait...");
setAlwaysOnTop(true);
setBackground(new java.awt.Color(227, 248, 115));
setModalityType(java.awt.Dialog.ModalityType.MODELESS);
setResizable(false);
setType(java.awt.Window.Type.POPUP);
jLabel_WaitMessage.setBackground(new java.awt.Color(242, 253, 153));
jLabel_WaitMessage.setText("WaitMessage");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel_WaitMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel_WaitMessage)
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel_WaitMessage;
// End of variables declaration//GEN-END:variables
}
刷新 JButton 调用名为“reload”的方法,该方法最初必须显示 jDialog,然后执行其余任务。 更具体地说:
public void reload(){
jTable_Activities.setEnabled(false); // freezes the JTable
JDialog_PleaseWait pleaseWaitDialog = new JDialog_PleaseWait("Communicating with database server...."); // create a new PleaseWait JDialog
pleaseWaitDialog.pack();
pleaseWaitDialog.setLocationRelativeTo(this); //relative to this frame
pleaseWaitDialog.setVisible(true); //display the JDialog
.... ....
// runs a DB query and updates a JTable
.... ....
所以,由于某种原因,JDialog 窗口弹出但 jLabel 没有显示...
我(我认为我)已经对其他工作正常的 JDialog 做了(确切的?)同样的事情,但是由于某些奇怪的原因,这个 JDialog 不能正常工作......
有什么提示吗?
【问题讨论】:
标签: java swing components jdialog