Hi..everybody...problem in dispose of JDialog

I am opening JDialog for showing some information in JApplet. When user disposes (Pressing Ok button) JDialog, JApplet looses focus and user is unable to stir through JApplet with the help of hotkeys.
Please help me to solve this problem

u can add a windowlistener to the dialog
addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
code to focus the applet
})

Similar Messages

  • Dispose a JDialog Object

    What is the correct procedures to dispose a JDialog Object for Garbage collection?
    Let's say d is a JDialog Object Do I need to do all of the following 2 instructions or just one of them?
    1......................d.dispose;
    2......................d=null;

    Could anyone help me?

  • Automatically dispose a JDialog after a certain time

    HI all,
    To dispose a JDialog by a user response I've add a button event and dispose it. Say user not click the button within one minute after displayed it. In that case I want to automatically dispose it. How can I do it.
    Thanks
    ItsJava

    Yes, I'm working on Timer as you said. What I'm asking in that code is what I tried. :) I think most of you think it is not a good approach at all :)
    Here what I try with the timer.
        public void autoHide(final JDialog mainDialog){
            int counter = 0;
            Timer timer = new Timer(1, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(mainDialog.isVisible()){
                         // In each second try to increment the counter by one
                         // if the counter is equal to 5 dispose the dialog
            timer.start();
        }I stuck here, I can't change the variable counter int the timer. IDE inform that used constant values.

  • Problem subclassing a modal JDialog

    Hi, I've run into a problem when creating a subclass of a class which itself extends JDialog. The problem is this:
    I have a class, lets call it SuperDialog, which extends JDialog. In the constructor, I set it to be a modal dialog. This works fine.
    However, when I try to create a subclass of SuperDialog, (lets call it SubclassDialog), this is where I run into difficulty. The problem is that the constructor for the SubclassDialog seems to get stuck when it calls on the constructor of SuperDialog, and does not do the rest of the constructor, which is really wierd, and I can't understand why.
    For example, if the constructor for the SubclassDialog is something like this:
    public SubclassDialog()
         super();   // The constructor gets stuck here
         do something here      // This code does not get executed
    }The 'do something here' code is not executed. The problem disappears if the SuperDialog is set to NOT modal. Can anyone explain to me why, and how to get round this problem? Here's a test program to illustrate what I'm on about. If you run the program, you will see the subclass dialog window appear containing the text "this is the superclass dialog" - the text SHOULD read "this is the subclass-dialog", because this was set in the subclass dialog constructor. Thanks for any help. James
    import javax.swing.*;
    import java.awt.Color;
    public class ModalDialogTest extends JFrame
        public static void main(String[] args)
            ModalDialogTest test = new ModalDialogTest();
            test.run();
        public void run()
            class SuperclassModalDialog extends JDialog
                protected JTextField text = new JTextField("This is the superclass dialog");
                public SuperclassModalDialog(JFrame frame)
                    super(frame, "This is the superclass dialog", true); 
                    // Setting this to 'false' eliminates the problem
                    frame.setVisible(true);
                    add(text);
                    pack();
                    setVisible(true);
            class SubclassModalDialog extends SuperclassModalDialog
                public SubclassModalDialog(JFrame frame)
                    super(frame);
                    text.setText("This is the SUBCLASS dialog");
            SubclassModalDialog dialog = new SubclassModalDialog(this);
    }

    Ah right, I see! Thanks a lot for that, solves my problem. Duke stars on their way!
    BTW, I'm curious why you would never subclass JDialog. I find that subclassing JDialog is a convenient way to create a pop-up window which blocks all other windows until it is closed - is there an easier / better way to do this?
    Thanks again,
    James

  • Probleme on JPopupMenu with JDialog

    I use JPopupMenu with JDialog. To display the popup, I use a mousePressed in a panel of the dialog:
    public void mousePressed(MouseEvent e) {
    if( e.getClickCount()==1 && e.getModifiers()==MouseEvent.BUTTON3_MASK && ga!=null ) {
         mpopup.show(e.getComponent(),e.getX(), e.getY());
    It works fine, but when a part of the popup is out of the dialog, the popup doesn't display.
    Is it normal?
    Has someone already had this problem?
    I work with jdk1.3.1_01
    Thanks for your help
    Templ

    When you create your popup menu do this :
    mpopup.setLightWeightPopupEnabled(false);
    I hope this helps,
    Denis

  • Problem to automatically adjust JDialog size

    Hello all,
    i have a form (JDialog) which consist of some jlabels and jtextfields.
    There is a JLable on the top of the JDialog - which will be used to show hints or errors.
    The user fill the form and press save.
    If the validation was not succeeded, the JLable on the top shows text.
    jlblText.setText("<html><body>Error. Please do this and that. </body></html>")
    view.pack();This text can have different length, so I put it in html tags for wrapping.
    The problem is: top JLable changes its height so, that all buttons and some text fields below go down and are invisible. JDialog doesn't adjust it's size, after the height of the lable was changed.
    The following code shows the same height of the jlable as it was before. No matter, whether I input 20 lines of text or 2 words.
    System.out.println("height = "+view.jlblText().getHeight());If I knew the real heigh of the jlable, I could adjust the size of the view.
    I don't know, why JDialog doesn't adjust it itself, if the height of the lable was changed.
    JScrollPane could solve my problem. But it can't be used in this case.
    Thanks in advance.

    Three suggestions:
    1) create a SSCCE so we can see your relevant code and play with it. Look here for more info on this:
    http://homepage1.nifty.com/algafield/sscce.html
    2) Repost this in the Swing forum. You've a better chance of getting good swing help there.
    3) Search through these forums, especially the Swing forum. This problem pops up at least once a week.
    Good luck!
    Message was edited by:
    petes1234

  • Hello everybody, Problem with Two panel in a Frame

    This is my first mail in this forum.I'm trying to learn java myself & have a problem in adding more than one panel in a JFrame.
    i should be able to add one panel which occupies 3/4 of a frame and another panel occupies the rest.
    Thanx in advance for anyone who helps me in sorting out this problem.

    You can use for example the GridLayout
    In your JFrame constructor, add lines below, it will add 2 colored panel in your frame
    Container container = getContentPane();
    container.setLayout(new GridLayout(1,2)); // 1 row, 2 cols
    JPanel panel1 = new JPanel();
    panel1.setBackground(Color.red);
    container.add(panel1);
    JPanel panel2 = new JPanel();
    panel2.setBackground(Color.green);
    container.add(panel2);

  • Problems with disposing frames

    im developing a GUI which, opens up a new frame when u press a button called 'control panel', in this new frame theres a button called 'connect' i use it to connect to a remote server, when its connected the server, the button is changed to 'disconnect' which obviously disconnects from the server. BUT when i close this control panel using the 'dispose()' method, and then when i open another instance of it, and press the disconnect button, it disconnects and automatically connects again (calling the action method twice) this is because there are 2 instace of the control panel open and i do not know how to fully delete and instance of one, it will keep happening for how many instance of control panel are open, e.g if i open and close the control panel 7 times, and press it connect/disconnected button it will loop 7 times. SO is there a way instead of using 'dispose' to completely delete an instance of a frame.
    thanks

    so what do u guys think i should do, how can i make it only have once instance of an actionListener despite the fact it could be opened and closed x ammount of times and it will do the action x times....
    some code...
    MainFrame (holds the button which opens the new frame)
      void procSettings_actionPerformed(ActionEvent e)
        procSettings s = new procSettings();
        s.setTitle("Processor Load Control Panel");
        s.setSize(370, 467);
        s.setLocationRelativeTo(null);
        s.setResizable(false);
        s.setVisible(true);
      }ProcSettings (frame with the disconnect / connect button)
      void line1Activate_actionPerformed(ActionEvent e)
        if(!MainFrame.procActive1)
          //connect
          Parser.connect1(line1SelectRNC.getSelectedItem(), "tch" + MainFrame.rncList[line1SelectRNC.getSelectedIndex() - 1][1]);
          line1Activate.setText("De-Activate");    // Changes the button to be a disconnect button
        else
          //disconnect
          Parser.disconnect1();
          line1Activate.setText("Activate");    // Changed the button to be a connect button
      }Now this connect fine the firs time, then i press the 'done' button (code below) which closes this frame and return to the program which carrys out the other functions. When I return to disconnect, I open another instance of ProcSettings and then i press De-Activate, its disconnects, then connects immediatly again (goes through the action method twice since the frame has been opened twice and this will continue for how many times the frame has been open)
    heres the done button in the ProcSettings
      void settingsDone_actionPerformed(ActionEvent e)
        dispose();
      }cheers for ur help guys...

  • Problem with JDialogs and Threads

    Hi. I'm new to this forum and I hope I'm not asking a repeat question. I didn't find what I needed after a quick search of existing topics.
    I have this problem with creating a new JDialog from within a thread. I have a class which extends JDialog and within it I'm running a thread which calls up another JDialog. My problem is that the JDialog created by the Thread does not seem to function. Everything is unclickable except for the buttons in the titlebar. Is there something that I'm missing out on?

    yeah, bad idea, don't do that.

  • Question about JDialog - dispose()

    I use in my application a custom JDialog to get inputs from the user.
    When the "ok" button is pressed, i store all the inputs i need inside an object and then i dispose the JDialog.
    Now, the code which made the JDialog retrieve the object containing all the inputs through a call to a method of my custom JDialog.
    But this happens after i called dispose() on my JDialog.
    According to what i understood about it, it should release all the resources related to the JDialog and all its own children, so, how can i possibly access to it after i have disposed it?
    The object is not destroyed?
    Is there a time interval before it is "destroyed"?
    Thanks,
    Nite

    According to what i understood about it, it should release all the resources related to the JDialog and all its own children, so, how can i possibly access to it after i have disposed it?Read more carefully.
    Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
    dispose() doesn't pre-empt the garbage collector. The native resources related to displaying the dialog are released, not the associated Java objects.
    Fresh resources will be obtained form the OS if the dialog is redisplayed.
    The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show.
    db

  • Dispose problem

    i cant even dispose the Splash that i created..can anyone here help me to fix it out..i already gone thought whole day..but stil the same..thx alot
    public static void main(String args[])
              Timer timer = new Timer();
              int times = 2000; // 2 sec
             Date timeToRun = new Date(System.currentTimeMillis()+ times);
             Splash kbsao=new Splash();
             timer.schedule(new TimerTask() {
                public void run()
                the problem--->     kbsao.dispose();
                        VerifierMain test = new VerifierMain();
            }, timeToRun);
         }     

    Or use java 6...
    http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/

  • JDialog not displaying correctly

    Hi all,
    Im having this problem with displaying a JDialog. I have a lengthy delay in my app and want to display an animated GIF while the user is waiting. The below code is what im trying to run. The JDialog wil display, but the title text, message text and the ImageIcon are not displayed on the JDialog. Anyone know what is wrong? Do i have to wait on the Image to load before i .show the dialog? But that wouldn't explain why the text doesn't show. Any help appreciated
    Code im trying to run, RemoteAdminMain.java
        WaitingDialog dialog = new WaitingDialog(this, "Connection...", false, "Creating Connection");
        try {
          //Create the connection...
          dialog.show();
          RemoteAdminMain.nc = NetConnection.createNetConnection(nodeAddress, Global.sessionUsername, Global.sessionPassword);
          dialog.dispose();
        } catch (Exception e) {
          dialog.dispose();
          JOptionPane.showMessageDialog(null, "Error", "Error", JOptionPane.ERROR_MESSAGE);
          e.printStackTrace();
          return;
    The Dialog code: WaitingDialog.java
    public class WaitingDialog extends JDialog {
      private JPanel panel1 = new JPanel();
      private BorderLayout borderLayout1 = new BorderLayout();
      private JLabel jLabel1 = new JLabel();
      private JLabel jLabel2 = new JLabel();
      public WaitingDialog(Frame frame, String title, boolean modal, String message) {
        super(frame, title, modal);
        try {
          jLabel2.setText(message);
          jbInit();
          pack();
        catch(Exception ex) {
          ex.printStackTrace();
        //Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dialogSize = getSize();
        if (dialogSize.height > screenSize.height) {
          dialogSize.height = screenSize.height;
        if (dialogSize.width > screenSize.width) {
          dialogSize.width = screenSize.width;
        setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
      public WaitingDialog() {
        this(null, "", false, "");
      void jbInit() throws Exception {
        panel1.setLayout(borderLayout1);
        jLabel2.setToolTipText("");
        jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel2.setHorizontalTextPosition(SwingConstants.CENTER);
        jLabel2.setText("message");
        jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
        ImageIcon icon = new ImageIcon(com.tempo.netservice.RemoteAdminMain.class.getResource("swing.gif"));
        icon.setImageObserver(jLabel1);
        jLabel1.setIcon(icon);
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.setResizable(false);
        this.setTitle("");
        getContentPane().add(panel1);
        panel1.add(jLabel1, BorderLayout.CENTER);
        panel1.add(jLabel2,  BorderLayout.SOUTH);
    }

    I fear the problem isn't with the JDialog itself, everything is from from that point of view. I forgot to mention that if you set it as Modal, it will display fine (however, the modal method is blocking, meaning the createNetConnection method will not be executed until the dialog is closed, entirly defeating the purpose.
    I believe the problem is that the createNetConnection function stops the rest of the JDialog from loading. So i guess my question to begin with is, is there anyway to completly display and paint the JDialog before allowing it to continue onto the next function?

  • HOW TO SHOW COMPONENT IN JDIALOG WHILE MAIN APP SLEEPING?

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-100)/2), (int)((300-50)/5*4), 100, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    }

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-100)/2), (int)((300-50)/5*4), 100, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    }

  • HOW TO SHOW JLABEL IN JDIALOG USE TIMERTASK WHILE MAIN CLASS IS SLEEPING?

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    // WHEN USER PRESS startThreadBtn it will make the application sleep for 15 secs and pop out JDialog window contain JLabel msg wrote "Please wait... program is sleeping"
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-100)/2), (int)((300-50)/5*4), 100, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    }

    LOUD NOISES.

  • HOW TO SHOW JLABEL IN JDIALOG  WHILE MAIN CLASS IS SLEEPING? (CODE EDITED)

    I have done a code below and it is working but the only problem is when the main program start to sleep by use Thread.sleep(10000) for 10 secs and it will prompt out a JDialog contain JLabel inside it with message "Please wait.... program is sleeping.". And when the thread ends the JDialog will auto disappear and it back to the main program.
    I am using TimerTask to run the JDialog while the main class is sleeping.
    The problem is:
    When the JDialog appear, it doesn't show the component so I only be able to view the JDialog window without contain any component. I already use container to add the component into JDialog but it still doesn't show. I only be able to see the JDialog window contain empty component when the main window is sleeping.
    How to make the components also appear in the JDialog when the main program is sleeping?
    Below is the code pls have a try:
    public class testThread extends JFrame
    public static void main(String args[])
    new testThread();
    public testThread()
    * other code not related is here
    // WHEN USER PRESS startThreadBtn it will make the application sleep for 15 secs and pop out JDialog window contain JLabel msg wrote "Please wait... program is sleeping"
    JButton startThreadBtn = new JButton("Start Thread");
    startThreadBtn.addActionListener
    ( new ActionListener()
    public void actionPerformed(ActionEvent e)
    try{
    doTask a = new doTask();
    java.util.Timer thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0); // when this code executed, will pop out a JDialog containing JLabel message --> refer to class doTask
    Thread.sleep(10000);
    a.terminate()
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    infoDialog = new JDialog(true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    Why I can not show the JLabel inside the JDialog? The JDialog window is opened but it contain empty component.
    PLEASE HELP ME .... THIS IS VERY URGENT

    I have the complete code and it is working. I can posted it here but it will be longer thats the reason why i shortened the code in here and displaying the important information.
    The problem is the JDialog only will display the JLabel after the thread woke up. Thats mean it is too late for me to display the information. I need the JLabel containing the information to be displayed when the thread is sleeping....
    Below is the complete code:
    you can have a try to recompile it and u will understand what i mean. It is working and the only problem is JLabel component did not displayed in the JDialog.
    Just copy the whole code into the txt file and save as testThread.java and recompile it. Inside the code has one inner class extends TimerTask call "doTask"
    THE CODE START BELOW:
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class testThread extends JFrame
    public static java.util.Timer thisTimer;
    public static doTask a;
    public static testThread tT;
    public Container cMain;
    public Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    public JButton exitBtn;
    public JButton startThreadBtn;
    /** Creates a new instance of testThread */
    public static void main(String args[])
    new testThread();
    public testThread()
    //System.out.println("Start to call JDialog");
    tT = this;
    int realW = (int)screenSize.getWidth();
    int realH = (int)screenSize.getHeight();
    int mainW = 500;
    int mainH = 300;
    exitBtn = new JButton("EXIT");
    exitBtn.setBounds((int)((500-100)/2), (int)((300-50)/5), 100, 50);
    exitBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    startThreadBtn = new JButton("Start Thread");
    startThreadBtn.setBounds((int)((500-200)/2), (int)((300-50)/5*4), 200, 50);
    startThreadBtn.addActionListener
    new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    System.out.println("Start to call JDialog");
    a = new doTask();
    thisTimer = new java.util.Timer();
    thisTimer.schedule(a, 0);
    System.out.println("Thread start to sleep first 10 secs");
    Thread.sleep(10000);
    System.out.println("Thread start to sleep second 5 secs");
    Thread.sleep(5000);
    System.out.println("Thread Wake Up");
    a.terminate();
    thisTimer.cancel();
    catch(InterruptedException ie)
    ie.printStackTrace();
    cMain = this.getContentPane();
    cMain.setLayout(null);
    cMain.add(exitBtn);
    cMain.add(startThreadBtn);
    setBounds((int)((realW-mainW)/2), (int)((realH-mainH)/2), mainW, mainH);
    setVisible(true);
    public class doTask extends TimerTask
    JDialog infoDialog;
    public void run()
    System.out.println("TASK IS RUNNING");
    int screenWidth = (int)screenSize.getWidth();
    int screenHeight = (int)screenSize.getHeight();
    int w = 300;
    int h = 200;
    infoDialog = new JDialog(tT, true);
    infoDialog.setTitle("Please Wait!!!");
    Container c = infoDialog.getContentPane();
    c.setLayout(new BorderLayout());
    JLabel infoLbl = new JLabel("Please Wait... Program is sleeping!!!", JLabel.CENTER);
    c.add(infoLbl, BorderLayout.CENTER);
    infoDialog.setBounds((int)((screenWidth-w)/2), (int)((screenHeight-h)/2), w, h);
    infoDialog.setVisible(true);
    public void terminate()
    infoDialog.setVisible(false);
    infoDialog.dispose();
    this.cancel();
    ******************************************************************************************************************************************************************************************************************************************

Maybe you are looking for

  • Transferring from IPOD

    I can't transfer from my IPOD back to my library. All the tunes on my IPOD were added from another computer I want to add them to my library so I can burn them onto a CD. Is this possible???

  • IViews to R/3 Infotypes

    How can I tell how an iView relates to an Infotype in R/3? Address iView in ESS to Address Infotype in R/3 which is easy. However, other iViews are not so obvious is there somewhere that tells you how they relate to each other?

  • Need some information on dataguard / streams for our scenerio !!

    Hi, We have a application with Oracle 11g ( will call it as Box 1 ) , currently apart form regular transaction load that we have, there are couple of other reporting apps also tapping/approaching our primary db (Box 1 ) which puts a lot of load on th

  • Sigsegv accessing va_arg with Sun Studio 12 Update 1 on OpenSolaris 2009.06

    $ uname -a SunOS ultra 5.11 snv_111b i86pc i386 i86pc Solaris $ cc -V cc: Sun C 5.10 SunOS_i386 2009/06/03 usage: cc [ options] files. Use 'cc -flags' for details $ cat testva.c #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <str

  • Multi-Card Reader not working

    I have an HP a6700f Product Number FQ565AA#ABA I have had Windows 8.1 Installed on it since it's been in beta and haven't had any hardware issues. BUt today i tried to put an SD card into the built in card reader and Windows doesn't even try to read