Results 1 to 9 of 9
Thread: JOptionPane stopping timer
- 08-06-2011, 10:02 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 19
- Rep Power
- 0
JOptionPane stopping timer
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?Java Code:JOptionPane.showMessageDialog(null, "Message", "Title", JOptionPane.INFORMATION_MESSAGE);
- 08-06-2011, 10:12 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
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.
- 08-06-2011, 11:20 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 19
- Rep Power
- 0
Ok, I made a dialog with modal set to false.
Problem is, it's a plain dialog box. How can I make the dialog box in the style of JOptionPane.INFORMATION_MESSAGE (if possible)?Java Code:JOptionPane pane = new JOptionPane(); JDialog dialog = pane.createDialog("Test"); dialog.setModal(false); dialog.setVisible(true);
- 08-07-2011, 03:56 AM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
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?
- 08-07-2011, 09:15 AM #5
Member
- Join Date
- Jun 2011
- Posts
- 19
- Rep Power
- 0
You mean this?
That obviously wasn't working, so I removed the parts that were giving me errors and came up with my code above.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;
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.
- 08-07-2011, 09:28 AM #6
Why should the Timer pause? SSCCE or it didn't happen.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.dbJava 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); } }
- 08-07-2011, 04:29 PM #7
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
I mean this:
What arguments did you use?Java Code:JOptionPane pane = new JOptionPane(arguments);
- 08-09-2011, 03:39 AM #8
Member
- Join Date
- Jun 2011
- Posts
- 19
- Rep Power
- 0
I used "JOptionPane.INFORMATION_MESSAGE" as an argument, but the dialog message goes there.
- 08-09-2011, 03:43 AM #9
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Similar Threads
-
stopping the thread
By kailash in forum Threads and SynchronizationReplies: 2Last Post: 02-06-2011, 01:21 PM -
Stopping a thread
By Arne in forum Threads and SynchronizationReplies: 9Last Post: 10-21-2010, 10:26 AM -
Stopping a Timer from Inside the timer
By krishnan in forum Java AppletsReplies: 2Last Post: 10-04-2010, 11:15 PM -
Stopping a .swf with java
By ercarls in forum New To JavaReplies: 2Last Post: 04-14-2010, 06:33 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks