?
Solved

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

Posted on 2009-07-10
12
Medium Priority
?
736 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
Technology Partners: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

649 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