Solved

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

Posted on 2009-07-10
12
684 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 128
jar file executable 12 37
MySQL  on Tomcat 8 23
arguments to jar 5 7
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

929 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

10 Experts available now in Live!

Get 1:1 Help Now