Dispose of JDialog by code, do not let the user close it

I have a short code, I would like to open a dialog, but I do not want the user to be able to close it, it just does not work, help me.

    import javax.swing.*;
    public class Processing extends JOptionPane{

    JDialog jd;
    public Processing(){
        super(null, JOptionPane.DEFAULT_OPTION, 
                  JOptionPane.INFORMATION_MESSAGE, null, new Object[]{});
        Icon processPic = new ImageIcon("C:\\Users\\Judit\\Desktop\\Mesekocka3D"
                + "\\externals\\pics\\szamitas.gif");

        setMessage(processPic);
        jd = createDialog("Számítás");

        jd.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        jd.setVisible(true);
        jd.dispose();
    }   
}

this is what my code looks like now, I'm using Jdialog instead of Joptionpane, do I have to write more characters for the website to accept my editing?

import javax.swing.*;



public class Mifasz
{
 private static class Processing extends JDialog{

public Processing(){
    Icon processPic = new ImageIcon("C:\\Users\\Judit\\Desktop\\Mesekocka3D"
            + "\\externals\\pics\\szamitas.gif");
    JLabel label = new JLabel(processPic);
    add(label);
    setTitle("Számítás");
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);        
    setSize(400, 70);
    setLocation(330, 300);
    setModal(true);
    setVisible(true);
    dispose();
}       
}

  public static void main(String[] args)
  {
    Processing pc = new Processing();
  }

}
+3
source share
4 answers

Ok, so I found a very simple solution: I just turn off the mainframe by processing. How to make JFrame Modal in Swing java

0
source

gif , , , - , joptionpane, , X, jdialog, optionpane X.

1) unecorated JDialog#setUndecorated(true);

2) gif Icon JLabel

3) Swing Timer , ooutput Swing Timer Swing Action actionPerformed JDialog#setVisible(fasle);

, , JCombobox.

1) JDialog ,

2) Swing Timer # repeat (false) , actionPerformed JDialog#setVisible(fasle);

3) Item (JComboBox) Icon JLabel myLabel#setIcon(myAnotherGIF)

4) invokeLater wrap JDialog#setVisible(true);

5)

6)

myIcon.getImage().flush();
myLabel.setIcon(myIcon);

, Icon's JLabel

+2

You need to call

jd.setVisible(false);

and then

jd.dispose();
+1
source

What you want to do is a splash screen, see this .

0
source

All Articles