?
Solved

open a JFileChooser/ modal window will block the event dispatching thread

Posted on 2009-07-10
12
Medium Priority
?
726 Views
Last Modified: 2013-11-23
Please tell me whether opening a JFileChooser/ modal window in event handling code will block the event dispatching thread.

Thank you
0
Comment
Question by:pdidominic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24822310
Yes it will. Use a SwingWorker
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 24822332
no it won't
0
 
LVL 92

Expert Comment

by:objects
ID: 24822347
If it did then opening JFileChooser would freeze up your gui
you'll find example and discussion here
http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 24822528
>>If it did then opening JFileChooser would freeze up your gui

(which is exactly what it does do)

All you need to do to demonstrate this is to try to close your main window with the file chooser dialog open
0
 

Author Comment

by:pdidominic
ID: 24823366
i have a little confuse here. Despite the JFileChooser dialog blocks the actionPerform event handling code as the following snippet but the event dispatching thread is still executed :-??

public class FileChooser extends JFrame
{
	public FileChooser()
	{
		initComponents();
		Runnable runner = new Runnable()
		{
			public void run()
			{
				ActionListener actionListener = new ActionListener()
				{
					public void actionPerformed(ActionEvent actionEvent)
					{
						testTxt.setText(testTxt.getText() + 'a');
						System.out.println(SwingUtilities.isEventDispatchThread());
					}
				};
				Timer timer = new Timer(500, actionListener);
				timer.start();
			}
		};
		EventQueue.invokeLater(runner);
	}
 
	public static void main(String[] args)
	{
		
		new FileChooser().setVisible(true);
		
	}
 
	private void startBtnActionPerformed(ActionEvent e)
	{
		JFileChooser fileChoose = new JFileChooser();
		
		System.out.println(SwingUtilities.isEventDispatchThread() + "---------");
		fileChoose.showOpenDialog(FileChooser.this);
		System.out.println(SwingUtilities.isEventDispatchThread() + "---------");
	}

Open in new window

0
 
LVL 26

Expert Comment

by:ksivananth
ID: 24823386
>>All you need to do to demonstrate this is to try to close your main window with the file chooser dialog open

I think, object is right, it will block UI( parent ) but not the event dispatching thread! if the event dispatching thread blocked, you will not see the drawing in the back UI, all will be greyed out!
0
 

Author Comment

by:pdidominic
ID: 24823393
in this snippet, i have a simple form with a textarea and a button. Pressing the button will open a file chooser dialog. I also have a Timer that constantly updates the textarea.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24824228
>>it will block UI( parent )

UIs don't get blocked - only threads get blocked ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24824285
http://en.wikipedia.org/wiki/Modal_window

Look at the first sentence under criticisms (which to me is absurd - if you don't want it to block workflow then don't make it modal)
0
 
LVL 92

Expert Comment

by:objects
ID: 24828305
> but the event dispatching thread is still executed :-??

thats because the event dispatch thread does *not* get blocked as I stated above.
0
 
LVL 92

Expert Comment

by:objects
ID: 24828378
> in this snippet, i have a simple form with a textarea and a button. Pressing the button will open a
> file chooser dialog. I also have a Timer that constantly updates the textarea.

And does it continue to update?  That should verify whether it is blocked or not.
0
 
LVL 92

Expert Comment

by:objects
ID: 24836892
(-:
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question