actionEvent + swingWorker + jOptionPane still lock the main Jframe
from an actionEvent ( popupmenu item ) the app start op that requiere user input data ( renaming some strings ).
I don't want this to be modal, user still being able to use other parts of the application ( menu, editor, etc... ) ; ok, you get the point :-).
So I first move the code into is own thread. Doesn't work : as soon as the joptionpane show up, user can't perforn no others actions until validation...
Move to swingworker : same. Checked and it's not in the eventdispacher thread.
privatevoid dirRenjMenuItemActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
final SwingWorker worker =new SwingWorker(){
public Object construct(){
// set some local var that might change
// this return false as it should !!
System.out.println("event dis ? : " + SwingUtilities.isEventDispatchThread() );
//blablabla, loops, exceptions, etc...
// display message and wait until answer from user
String s = JOptionPane.showInputDialog( .............. );
//blablabla again, check answer etc...
return(null );
}
};
worker.start();
System.out.println("this string display prior of joptionpane show up !!!?");
}
swingworker isn't suppose to resolve such problems ?
how can I do this without making my own messages boxes + events connection ?
( ie keeping a simple code like this :-) )
thks
[2098 byte] By [
j.lea] at [2007-10-2 13:58:25]

> the app start op that requiere user input data ( renaming some strings ). I don't want this to be modal,
Well, this doesn't make sense. If you have required input it should be modal. Otherwise the user can use the application without ever entering the "required data", since you have no way to force them to go to the dialog an enter the data.
Anyway, when you create and show a JOptionPane using the show? methods the created JDialog is always modal, so using a SwingWorker or a separate Thread won't do anything.
Read the JOptionPane API, it shows you how to "Create and Use a JOptionPane Directly". Using this approach you can then make the dialog non-modal.
Although I'm not really sure this will help you since you will need to restructure your program to actually retrieve the user input since the processing will not wait until the dialog is closed.
Thank for repling so quickly !!!!
> > the app start op that requiere user input data (
> renaming some strings ). I don't want this to be
> modal,
>
> Well, this doesn't make sense. If you have required
> input it should be modal. Otherwise the user can use
> the application without ever entering the "required
> data", since you have no way to force them to go to
> the dialog an enter the data.
>
actually it does :-) modal for a specific task wouldn't mean always modal for the entire application. For exemple think about some search dialog boxes in mozilla, netbeans... or a text editor. just because user is requested to enter search string he can still scroll the text, open new doc etc...
> Anyway, when you create and show a JOptionPane using
> the show? methods the created JDialog is always
> modal, so using a SwingWorker or a separate Thread
> won't do anything.
>
i wasn't sure. in doc is "the current thread", since I create a new one i was a little confused. So it's the main thread.
> Read the JOptionPane API, it shows you how to "Create
> and Use a JOptionPane Directly". Using this approach
> you can then make the dialog non-modal.
>
I were trying to avoid that. so i have to replace a few lines in about 10 dlg for gui +events+ etc... trivial but boring :-). that going to make the code more complex and confusing.
> Although I'm not really sure this will help you since
> you will need to restructure your program to actually
> retrieve the user input since the processing will not
> wait until the dialog is closed.
actually that help a lot :-)
thks, i'll try that.
j.lea at 2007-7-13 12:03:44 >
