Results 1 to 9 of 9
  1. #1
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default JOptionPane stopping timer

    Java Code:
    JOptionPane.showMessageDialog(null, "Message", "Title", JOptionPane.INFORMATION_MESSAGE);
    I have this JOptionPane that pops up a message while a timer is running on my desktop application. The timer and main program will pause until I press ok. Is there any way to keep everything running while a JOptionPane pops up, or do I have to create a custom dialog?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Read the JOptionPane API. It shows you how to "Create and use an opttion pane directly". This allows you have access to the diallog before it is made visible so you can set the dialog non-modal.

  3. #3
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    Ok, I made a dialog with modal set to false.

    Java Code:
    JOptionPane pane = new JOptionPane();
    JDialog dialog = pane.createDialog("Test");
    dialog.setModal(false);
    dialog.setVisible(true);
    Problem is, it's a plain dialog box. How can I make the dialog box in the style of JOptionPane.INFORMATION_MESSAGE (if possible)?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Why is it so hard to follow the example given in the API?

    What is different between the sample code in the API description and the code you just posted?

  5. #5
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    You mean this?
    Java Code:
    JOptionPane pane = new JOptionPane(arguments);
         pane.set.Xxxx(...); // Configure
         JDialog dialog = pane.createDialog(parentComponent, title);
         dialog.show();
         Object selectedValue = pane.getValue();
         if(selectedValue == null)
           return CLOSED_OPTION;
         //If there is not an array of option buttons:
         if(options == null) {
           if(selectedValue instanceof Integer)
              return ((Integer)selectedValue).intValue();
           return CLOSED_OPTION;
         }
         //If there is an array of option buttons:
         for(int counter = 0, maxCounter = options.length;
            counter < maxCounter; counter++) {
            if(options[counter].equals(selectedValue))
            return counter;
         }
         return CLOSED_OPTION;
    That obviously wasn't working, so I removed the parts that were giving me errors and came up with my code above.

    I tried dozens of combinations of my code above with "JOptionPane.INFORMATION_MESSAGE" to try and create an information message JOptionPane... but none worked, which is why I posted the code I had so far for additional help.

    I was only able to create a plain dialog box, but I wanted an information message JOptionPane that's not modal, if it's even possible.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    I have this JOptionPane that pops up a message while a timer is running on my desktop application. The timer and main program will pause until I press ok.
    Why should the Timer pause? SSCCE or it didn't happen.
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    public class ModalTimerPause {
    
      public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
    
          @Override
          public void run() {
            new ModalTimerPause().makeUI();
          }
        });
      }
    
      public void makeUI() {
        final JLabel label = new JLabel("0");
        Timer timer = new Timer(300, new ActionListener() {
    
          int count;
    
          @Override
          public void actionPerformed(ActionEvent e) {
            label.setText("" + count++);
          }
        });
    
        JButton button = new JButton("Click");
        button.addActionListener(new ActionListener() {
    
          @Override
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Modal Dialog");
          }
        });
        JFrame frame = new JFrame();
        frame.add(label, BorderLayout.NORTH);
        frame.add(button, BorderLayout.SOUTH);
        timer.start();
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    }
    db

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    I mean this:

    Java Code:
    JOptionPane pane = new JOptionPane(arguments);
    What arguments did you use?

  8. #8
    a_programmer is offline Member
    Join Date
    Jun 2011
    Posts
    19
    Rep Power
    0

    Default

    I used "JOptionPane.INFORMATION_MESSAGE" as an argument, but the dialog message goes there.

  9. #9
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    So use a different constructor. I can't tell you which one you want, You have to read the API yourself and use the appropriate constructor that will create and build the option pane the way you want.

Similar Threads

  1. stopping the thread
    By kailash in forum Threads and Synchronization
    Replies: 2
    Last Post: 02-06-2011, 01:21 PM
  2. Stopping a thread
    By Arne in forum Threads and Synchronization
    Replies: 9
    Last Post: 10-21-2010, 10:26 AM
  3. Stopping a Timer from Inside the timer
    By krishnan in forum Java Applets
    Replies: 2
    Last Post: 10-04-2010, 11:15 PM
  4. Stopping a .swf with java
    By ercarls in forum New To Java
    Replies: 2
    Last Post: 04-14-2010, 06:33 PM
  5. Replies: 0
    Last Post: 04-04-2008, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •