Solved

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

Posted on 2009-07-10
12
682 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
  • 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 500 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now