Solved

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

Posted on 2009-07-10
12
717 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 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

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!

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

726 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