I'm developing an application that will execute a processing soon, and I want a message warning that the process is running stay on the screen while it does this processing. I tried to do with JOptionPane
, but since it is a modal window by default the processing will only continue if it is closed. So I made a simple window with JDialog
, but after doing the instance of it and giving a .setVisible(true);
it does not draw the components that it owns. The process behind it usually occurs, and the window closes, so it is not crashing.
Follow the code in the window:
package main;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
public class IndexAndo extends JDialog {
private final JPanel contentPanel = new JPanel();
private JLabel lblIstoPodeLevar;
private JLabel lblIndexandoAguarde;
/**
* Create the dialog.
*/
public IndexAndo() {
setTitle("IR - Indexar");
setBounds(100, 100, 450, 150);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
{
lblIstoPodeLevar = new JLabel("Isto pode levar alguns minutos.");
lblIstoPodeLevar.setFont(new Font("Tahoma", Font.BOLD, 11));
}
{
lblIndexandoAguarde = new JLabel("Executando indexa\u00E7\u00E3o, aguarde.");
lblIndexandoAguarde.setFont(new Font("Tahoma", Font.BOLD, 11));
}
GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
gl_contentPanel.setHorizontalGroup(
gl_contentPanel.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPanel.createSequentialGroup()
.addContainerGap(126, Short.MAX_VALUE)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
.addComponent(lblIndexandoAguarde)
.addGap(115))
.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
.addComponent(lblIstoPodeLevar)
.addGap(118))))
);
gl_contentPanel.setVerticalGroup(
gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPanel.createSequentialGroup()
.addGap(26)
.addComponent(lblIndexandoAguarde)
.addGap(9)
.addComponent(lblIstoPodeLevar)
.addContainerGap(39, Short.MAX_VALUE))
);
contentPanel.setLayout(gl_contentPanel);
}
}