Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Cannot open a Swing JFrame when using OSGi
Cannot open a Swing JFrame when using OSGi [message #81663] Sun, 21 January 2007 09:48 Go to next message
Eclipse UserFriend
Originally posted by: alterego.clear.net.nz

Hi all,

I am developing using Eclipse 3.2.1, JDK5.0 on Max OS X 10.4.

I have a plugin project which defines an Application and a Product. I launch the Application using an Eclipse Application launch target from within the IDE (selecting the 'Run an Application' option on the Main tab in the launch configuration).

The dependencies for my plugin project are:

<pre>
org.eclipse.equinox.common_3.2.0.v20060603.jar
org.eclipse.core.runtime_3.2.0.v20060603.jar
org.eclipse.core.contenttype_3.2.0.v20060603.jar
org.eclipse.core.jobs_3.2.0.v20060603.jar
org.eclipse.core.runtime.compatibility.auth_3.2.0.v20060601. jar
org.eclipse.equinox.preferences_3.2.1.R32x_v20060717.jar
org.eclipse.equinox.registry_3.2.1.R32x_v20060814.jar
</pre>

So there are no RCP, SWT or JFace dependencies.

The code for my Application looks like this:

<pre>
package my.application;

import javax.swing.JFrame;

import org.eclipse.core.runtime.IPlatformRunnable;

public class Application implements IPlatformRunnable {

public Object run(Object args) throws Exception {
try {
System.out.println("opening frame");
JFrame frame = new JFrame("Test");
frame.setSize(100, 100);
frame.validate();
frame.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
}
return IPlatformRunnable.EXIT_OK;
}
}
</pre>

When I launch the Application, it exits immediately. Stepping through using the debugger reveals that when frame.setVisible(true) is called, the call returns immediately. No JFrame is ever shown.

If I run this class as a normal Java application, for example by adding the following code and just running it directly:

<pre>
public static void main(String... args) {
try {
new Application().run(args);
}
catch (Exception e) {
e.printStackTrace();
}
}
</pre>

Then it works as expected, the JFrame is opened.

Is there some reason why Swing doesn't work when launched as an Eclipse Application? Is this a problem with OS X? I haven't had the opportunity to try this on Windows yet, so don't know if it works there.

Thanks,
Jesse.
Re: Cannot open a Swing JFrame when using OSGi [message #81682 is a reply to message #81663] Sun, 21 January 2007 12:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

There have been problems with the SWT_AWT bridge (which supports the JFrame that you're trying to create) on Mac OS X. I believe that it is fixed, but maybe not until the Eclipse 3.3 stream. Have you tried this with Eclipse 3.3M4?

Alex.
Re: Cannot open a Swing JFrame when using OSGi [message #81695 is a reply to message #81663] Sun, 21 January 2007 18:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alterego.clear.net.nz

I just tried this with Eclipse 3.3M4. Same result as before, no JFrame is opened. Also, I noticed the following messages are output to std err as a result of instantiating JFrame (this also occurs with Eclipse 3.2.1):

<pre>
2007-01-21 18:05:51.323 java[1969] [Java CocoaComponent compatibility mode]: Enabled
2007-01-21 18:05:51.323 java[1969] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
</pre>

Regardless, I would have thought that the SWT_AWT bridge would not be needed, since my code has no dependency on SWT or JFace at all, just the Eclipse OSGi and core runtime stuff. So why would this prevent me using Swing?

Thanks and regards,
Jesse.
Re: Cannot open a Swing JFrame when using OSGi [message #81814 is a reply to message #81695] Wed, 24 January 2007 21:18 Go to previous message
Martin Lippert is currently offline Martin LippertFriend
Messages: 124
Registered: July 2009
Senior Member
Hi Jesse,

I am using Swing quite successfully on top of Equinox without any
problems in a large project and I think it is a great idea to implement
general Swing apps on top of Equinox.

The problem with the IPlatformRunnable and the Swing frame is that the
runtime shuts down the system when the control flow comes back from the
run method. This is different from opening the Swing frame from the main
method. We got around this problem by manually waiting for the Swing
frame to close within the run method.

For example:

public Object run(Object args) throws Exception {
final Object lock = new Object();
JFrame frame = new JFrame("Hello World");
JButton exitButton = new JButton("Exit");
exitButton.setActionCommand("exit");
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
synchronized(lock) {
lock.notify();
}
}
});

frame.getContentPane().add(exitButton);
frame.pack();
frame.show();

synchronized(lock) {
lock.wait();
}

return EXIT_OK;
}

This (or similar code) should solve your problem.

-Martin



Jesse wrote:
> I just tried this with Eclipse 3.3M4. Same result as before, no JFrame is opened. Also, I noticed the following messages are output to std err as a result of instantiating JFrame (this also occurs with Eclipse 3.2.1):
>
> <pre>
> 2007-01-21 18:05:51.323 java[1969] [Java CocoaComponent compatibility mode]: Enabled
> 2007-01-21 18:05:51.323 java[1969] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
> </pre>
>
> Regardless, I would have thought that the SWT_AWT bridge would not be needed, since my code has no dependency on SWT or JFace at all, just the Eclipse OSGi and core runtime stuff. So why would this prevent me using Swing?
>
> Thanks and regards,
> Jesse.
Previous Topic:using servletbridge with RCP application and PDE
Next Topic:loading other classes with equinox in servlet container
Goto Forum:
  


Current Time: Fri Apr 26 20:53:05 GMT 2024

Powered by FUDForum. Page generated in 0.03173 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top