Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » No frame contents in Swing app on Virgo
No frame contents in Swing app on Virgo [message #664513] Sun, 10 April 2011 12:26 Go to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
Hello everyone.

I am deploying a very simple Swing application to Virgo which instantiates a JFrame containing a JToolBar and a JLabel.

The JFrame appears without problems, but it has no contents. The same code works works fine if run standalone via the main() method.

I am attaching the source code for the bundle. Any idea as to what is wrong?

TIA,
Barbara

[Updated on: Sun, 10 April 2011 12:26]

Report message to a moderator

Re: No frame contents in Swing app on Virgo [message #664525 is a reply to message #664513] Sun, 10 April 2011 17:35 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
I decided to test this in an Equinox OSGi runtime via Eclipse and it works fine there. So this seems to point to a Virgo related problem.

Thanks,
B.
Re: No frame contents in Swing app on Virgo [message #664660 is a reply to message #664525] Mon, 11 April 2011 10:32 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Virgo applies some hooks to Equinox to modify its behaviour, but it is not clear that the hooks will make any difference to this application.

The most obvious line of attack is to debug through the bundle activator and see what happens to the API calls that should paint the missing content. Is an exception thrown, for example?

You could also compare the wiring of the bundle in both Virgo and Equinox, although it is so simple, it is hard to imagine it being much different.
Re: No frame contents in Swing app on Virgo [message #664662 is a reply to message #664660] Mon, 11 April 2011 10:38 Go to previous messageGo to next message
Joel Rosi-Schwartz is currently offline Joel Rosi-Schwartz
Messages: 624
Registered: July 2009
Location: London. England
Senior Member
Glyn, would you have the time to try this in 3.0 just to see if the behaviour is the same?
Re: No frame contents in Swing app on Virgo [message #664670 is a reply to message #664662] Mon, 11 April 2011 10:55 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
I'd like to, but I am up to my neck in other issues at the moment.

The first thing I'd ask for is a binary bundle and any pre-reqs that need to be installed. But it would be quicker for you or Barbara to try it out on a 3.0 milestone.

I would be surprised if the behaviour has changed, but it's worth a shot.
Re: No frame contents in Swing app on Virgo [message #664676 is a reply to message #664660] Mon, 11 April 2011 11:05 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
Glyn,

Thanks for your hints.

I have run the code through the debugger, but no revelation. No exceptions are thrown and the frame's component hierarchy is as expected. In summary, nothing that is obviously going wrong there.

[Updated on: Mon, 11 April 2011 11:09]

Report message to a moderator

Re: No frame contents in Swing app on Virgo [message #664682 is a reply to message #664676] Mon, 11 April 2011 11:12 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
It *could* be a Swing bug of course. How deeply did you debug?
Re: No frame contents in Swing app on Virgo [message #664688 is a reply to message #664682] Mon, 11 April 2011 11:33 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
Well, I did not get to the point of individual pixel painting.. Razz

I am curious to understand what you mean exactly by a "Swing bug", seeing how the little app works fine standalone and in an Equinox container.
Re: No frame contents in Swing app on Virgo [message #664698 is a reply to message #664688] Mon, 11 April 2011 12:00 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
BTW, I forgot to mention that I did set my debugger to stop at caught and uncaught exceptions, just in case an exception was thrown and consumed, and verified that no exceptions were being thrown.
Re: No frame contents in Swing app on Virgo [message #664709 is a reply to message #664698] Mon, 11 April 2011 12:20 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo Iliev
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

Have you tested the app on a different platform (Linux/Windows)?
Re: No frame contents in Swing app on Virgo [message #664798 is a reply to message #664688] Tue, 12 April 2011 02:22 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Barbara Rosi-Schwartz wrote on Mon, 11 April 2011 16:33
Well, I did not get to the point of individual pixel painting.. Razz

I am curious to understand what you mean exactly by a "Swing bug", seeing how the little app works fine standalone and in an Equinox container.

Er, I mean a bug in Swing, possibly one triggered by the Virgo environment. We've seen other areas of code that do weird class loading and resource lookup logic and which behave differently in OSGi. Virgo's Equinox hooks make it behave differently from Equinox.

I admit a Swing bug seems unlikely, but there again so does a Virgo bug having such an effect on Swing.
Re: No frame contents in Swing app on Virgo [message #664799 is a reply to message #664670] Tue, 12 April 2011 02:23 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Did you try it on a 3.0 milestone BTW?
Re: No frame contents in Swing app on Virgo [message #664806 is a reply to message #664799] Tue, 12 April 2011 03:25 Go to previous messageGo to next message
Joel Rosi-Schwartz is currently offline Joel Rosi-Schwartz
Messages: 624
Registered: July 2009
Location: London. England
Senior Member
Glyn Normington wrote on Tue, 12 April 2011 07:23
Did you try it on a 3.0 milestone BTW?


Yes I did last night on OS X and surprisingly it does work somewhat differently. Recall that on OS X I get the failure on the Aqua look-and-feel with 2.1.0, but on 3.0M3 there is no exception but the window still does not appear. Barbara started to look at on my machine but it too late so we quit and will pick it up this morning. We will set up 3.0 on her Win7 machine to isolate our efforts from OS X vagaries.

Re: No frame contents in Swing app on Virgo [message #664809 is a reply to message #664806] Tue, 12 April 2011 03:41 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
My inquisitiveness got the better of me and I tried this out on a development build of the Virgo 3.0 kernel. Under a debugger the following error was thrown:
java.lang.Error: Cannot load com.apple.laf.AquaLookAndFeel


In fact as soon as I tried to step over the new JFrame statement in the Activator, the debugger stopped on that error.
Re: No frame contents in Swing app on Virgo [message #664816 is a reply to message #664798] Tue, 12 April 2011 03:56 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
Hi Glyn.

My apologies, in my rush yesterday I did forget to tick a checkbox during my debugging and I was not catching all exceptions. Embarrassed

Turns out that, under Virgo 2.1.0 and on the Windows 7 machine, I get all sorts of ClassNotFoundExceptions when I am trying to create the JFrame, mostly to do with look and feel etc.

So your diagnosis of possible class loader issues is probably very accurate.

Can you give me a hint on how to proceed with this? Or is it a hopeless cause?

[Updated on: Tue, 12 April 2011 03:56]

Report message to a moderator

Re: No frame contents in Swing app on Virgo [message #664819 is a reply to message #664809] Tue, 12 April 2011 04:00 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Problem solved! Read on...

Next thing I noticed was some error handling in java.awt.EventDispatchThread:
            /* Load the class, instantiate it, and find its handle method */
            Method m;
            Object h;
            try {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                Class c = Class.forName(handlerClassName, true, cl);
                m = c.getMethod("handle", new Class[] { Throwable.class });
                h = c.newInstance();
            } catch (Throwable x) {
                handlerClassName = NO_HANDLER; /* Do not try this again */
                return false;
            }

Stepping in to the forName call, the class name was "apple.awt.CToolkit$EventQueueExceptionHandler" and the class loader was the application's bundle class loader. So the JDK is making a hierarchical class loader assumption that the bundle class loader will be able to load this class. This is the kind of thing I was talking about when I mentioned a bug in Swing, except this time it's a bug in AWT. However, there is a workaround as this situation is not entirely uncommon.

I added apple.* and, on a hunch, com.apple.* to the org.osgi.framework.bootdelegation property in lib/java6-server.profile and then the application behaved like it did under Equinox. ("Look mum!" was visible, for example.)

I presume Equinox's default boot delegation settings differ from those configured in Virgo.
Re: No frame contents in Swing app on Virgo [message #664820 is a reply to message #664819] Tue, 12 April 2011 04:05 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
Oh that's fantastic!

Now what do I need to add to your magic properties file to get it to work under Windows7? (That is, after all, the primary platform for my project)
Re: No frame contents in Swing app on Virgo [message #664821 is a reply to message #664820] Tue, 12 April 2011 04:06 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
That's an exercise for the reader. Wink

Try com.sun.* as sun.* is already there.
Re: No frame contents in Swing app on Virgo [message #664823 is a reply to message #664821] Tue, 12 April 2011 04:22 Go to previous messageGo to next message
Barbara Rosi-Schwartz is currently offline Barbara Rosi-Schwartz
Messages: 448
Registered: July 2009
Senior Member
Ok, the first exception I am getting is a ClassNotDefFoundException from the ClasspathManager (line 495), when it is trying to look for class with classname "javax.swing.plaf.basic.BasicPanelUI" (stacktrace below)

What does that tell you?
[org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:495), 
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:469), 
org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:449), 
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216), 
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:393), 
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:469), 
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422), 
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410), 
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107), 
org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:135),
java.lang.ClassLoader.loadClass(ClassLoader.java:248), 
java.lang.Class.forName0(Native Method), java.lang.Class.forName(Class.java:247), 
javax.swing.SwingUtilities.loadSystemClass(SwingUtilities.java:1850), 
javax.swing.UIDefaults.getUIClass(UIDefaults.java:666), 
javax.swing.UIDefaults.getUI(UIDefaults.java:738), 
javax.swing.UIManager.getUI(UIManager.java:989), 
javax.swing.JPanel.updateUI(JPanel.java:109), 
javax.swing.JPanel.<init>(JPanel.java:69), 
javax.swing.JPanel.<init>(JPanel.java:92), 
javax.swing.JPanel.<init>(JPanel.java:100), 
javax.swing.JRootPane.createGlassPane(JRootPane.java:528), 
javax.swing.JRootPane.<init>(JRootPane.java:348), 
javax.swing.JFrame.createRootPane(JFrame.java:255), 
javax.swing.JFrame.frameInit(JFrame.java:236), 
javax.swing.JFrame.<init>(JFrame.java:203), 
org.foo.prova.Activator.init(Activator.java:42), 
org.foo.prova.Activator.access$0(Activator.java:41), 
org.foo.prova.Activator$1.run(Activator.java:36), 
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209), 
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:642), 
java.awt.EventQueue.access$000(EventQueue.java:85), 
java.awt.EventQueue$1.run(EventQueue.java:603), 
java.awt.EventQueue$1.run(EventQueue.java:601), 
java.security.AccessController.doPrivileged(Native Method), 
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87), 
java.awt.EventQueue.dispatchEvent(EventQueue.java:612), 
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269), 
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184), 
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174), 
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169), 
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161), 
java.awt.EventDispatchThread.run(EventDispatchThread.java:122)]


[Updated on: Tue, 12 April 2011 04:29]

Report message to a moderator

Re: No frame contents in Swing app on Virgo [message #664826 is a reply to message #664819] Tue, 12 April 2011 04:28 Go to previous messageGo to next message
Joel Rosi-Schwartz is currently offline Joel Rosi-Schwartz
Messages: 624
Registered: July 2009
Location: London. England
Senior Member
Glyn Normington wrote on Tue, 12 April 2011 09:00
Problem solved! Read on...




Neat!!!!

But, I have just done the same here using 2.1.0 and while I do get rid of the AquaLookAndFeel exception I do not get a Swing app visualising. Are you using 3M3? Let me know and I will try that.

But, just the fact that you can get the prova, with text, buttons and all is great. That is what is missing on Win7, so it appears that we might not be fighting windmill after all. Just need to find the right combo of assets that work, Then maybe we can work backwards to find out where and why the others fail.

Cheers,
Joel
Re: No frame contents in Swing app on Virgo [message #664831 is a reply to message #664826] Tue, 12 April 2011 04:47 Go to previous messageGo to next message
Joel Rosi-Schwartz is currently offline Joel Rosi-Schwartz
Messages: 624
Registered: July 2009
Location: London. England
Senior Member
Okay, Glyn, I just tried it in 3.0M3 on OS X with your fix and it works perfectly. So there is a difference between 2.1 and 3.0M3 Smile

Next step is that I setup 3.0M3 on Win7 and see how we fare. Will keep you posted.
Re: No frame contents in Swing app on Virgo [message #664835 is a reply to message #664831] Tue, 12 April 2011 05:03 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
The class loading behaviour hasn't changed much, if at all, between 2.1 and 3.0M3. Did you configure the boot delegation property the same in both cases?

We upgraded Equinox for 3.0, so that may be something to do with the difference.
Re: No frame contents in Swing app on Virgo [message #664840 is a reply to message #664835] Tue, 12 April 2011 05:16 Go to previous messageGo to next message
Joel Rosi-Schwartz is currently offline Joel Rosi-Schwartz
Messages: 624
Registered: July 2009
Location: London. England
Senior Member
Glyn Normington wrote on Tue, 12 April 2011 10:03
The class loading behaviour hasn't changed much, if at all, between 2.1 and 3.0M3. Did you configure the boot delegation property the same in both cases?

We upgraded Equinox for 3.0, so that may be something to do with the difference.


Guess what? Put 3.0M3 on Win7 and prova still would not work. Looking at java6-server.profile I decided to take a shot and put javax.* into org.osgi.framework.bootdelegation property. And guess what, it all started to work fine Smile

NOW I KNOW that I do not fully understand the ramifications of brute force putting javax.* into the boot delegator, so I need guidance in what can and should not be done here.

Btw, Barbara has now got the paint demo working on 3.0M3 in its full glory. We are almost there now, just have to set up a second repo host in M3 to get the last piece of the her infrastructure into place.

Joel
Re: No frame contents in Swing app on Virgo [message #664852 is a reply to message #664840] Tue, 12 April 2011 05:35 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn Normington
Messages: 1222
Registered: July 2009
Senior Member
Start by reading the OSGi R4.2 Core specification (available from www.osgi.org), section 3.8.3 Parent Delegation.

Essentially for packages available from the application class loader (AKA the "system" class loader) such as those included in the JRE, you either have to import them in your application and ensure they are exported from the system bundle by changing the org.osgi.framework.system.packages property in java6-server.profile or boot delegate them and not import them into your application.

The downside of boot delegating is that your application then has an implicit dependency on the environment (specifically on the boot delegation property) and so it will not fail to resolve if the relevant packages are unavailable.

Therefore adding javax.* to boot delegation is probably overkill. If some other application running on the server wanted to import a javax package from a bundle, then the classes of the javax package wouldn't be loaded from the bundle but from the application class loader instead.

If you can be more specific with the boot delegation property, e.g. javax.swing.*, that would be safer.

[Updated on: Tue, 12 April 2011 05:37]

Report message to a moderator

Re: No frame contents in Swing app on Virgo [message #1028473 is a reply to message #664513] Thu, 28 March 2013 05:47 Go to previous message
Miroslav Lansky is currently offline Miroslav Lansky
Messages: 1
Registered: March 2013
Junior Member
Hi I had same problem with virgo-tomcat-server 3.6 on Win7 and OpenSUSE 12.3, solution for both systems is simple: to java6-server.profile add line javax.swing.*,\ in org.osgi.framework.bootdelegation section
Previous Topic:Remote Node Management
Next Topic:Virgo 3.6.1 admin console/ssh issues
Goto Forum:
  


Current Time: Fri Apr 18 06:54:27 EDT 2014

Powered by FUDForum. Page generated in 0.10652 seconds