[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.rcp] Re: Problem using Swing from org.eclipse.core.runtime.applications extension
|
What happens in a regular Java application is that Swing will create an
additional thread. The call to setVisible(true) causes the thread to be
created, but never blocks. The VM stays running the Swing thread, while
the main thread runs the main method to completion and ends.
The difference is that in Eclipse, when the application finishes running,
Eclipse will start the shutdown sequence. And the last step in the
shutdown sequence is to call System.exit(), what will exit the VM no
matter how many threads are currently running.
Your application should block waiting (using a monitor, for instance)
until you believe it is time to exit (the windowClosing event, for
instance). In the callback for that event, you could notify the monitor so
the main thread would complete running, and Eclipse's shutdown sequence
could start.
Rafael
Harold Mills wrote:
> I have an existing Swing application to which I would like to add plug-in
> support. I hope to use the Eclipse plug-in facility for this purpose. To
> convince myself that this can work, I'm trying to write a small Eclipse
> plug-in containing an org.eclipse.core.runtime.applications extension as
> follows:
> package clo.brp.rcp;
> import javax.swing.JFrame;
> import org.eclipse.core.runtime.IPlatformRunnable;
> public class RcpApplication implements IPlatformRunnable {
> public Object run(Object args) {
> JFrame frame = new JFrame("RcpApplication");
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> frame.setVisible(true);
> System.out.println("back from setVisible");
> return IPlatformRunnable.EXIT_OK;
> }
> }
> This almost works, except that the call to frame.setVisible returns
> immediately instead of blocking until the user dismisses the JFrame, the
> normal behavior for a Swing application. So the JFrame appears only
> briefly and then the program exits. Does anybody know how I can fix this?