Skip to main content



      Home
Home » Eclipse Projects » Kura » GUI swing on OSGI bundle in KURA(Create an osgi bundle that shows gui on HDMI screen )
GUI swing on OSGI bundle in KURA [message #1731018] Mon, 02 May 2016 05:21 Go to next message
Eclipse UserFriend
I need help to create a bundle in Kura that show a Swing's GUI. I'm using Java and OSGI to create bundles. I run it on raspberryPI with a HDMI screen.

I put this code inside the bundle's activator:

public void activate(ComponentContext componentContext, Map<String,Object> properties)
{
System.out.println("Sono AstroGUI!!!!");

Runnable runnable = new Runnable() {
public void run() {
createAndShow();
}
};
SwingUtilities.invokeLater(runnable);
}

static void createAndShow() {


JFrame frame = new JFrame("Hello World");
frame.setSize(640,480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

But when I upload the bundle, the system return this error:

Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207) at java.awt.Window.(Window.java:536) at java.awt.Frame.(Frame.java:420) at javax.swing.JFrame.(JFrame.java:225) at com.riccardofontanini.astrogui.AstroGUIActivator.createAndShow(AstroGUIActivator.java:56) at com.riccardofontanini.astrogui.AstroGUIActivator$1.run(AstroGUIActivator.java:47) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744) at java.awt.EventQueue.access$400(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:697) at java.awt.EventQueue$3.run(EventQueue.java:691) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:714) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


Thank you,
Riccardo Fontanini
Re: GUI swing on OSGI bundle in KURA [message #1731037 is a reply to message #1731018] Mon, 02 May 2016 08:50 Go to previous messageGo to next message
Eclipse UserFriend
You can check this;
http://stackoverflow.com/questions/662421/no-x11-display-variable-what-does-it-mean

Thanks,
Said.

Re: GUI swing on OSGI bundle in KURA [message #1731111 is a reply to message #1731037] Mon, 02 May 2016 17:23 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

I have also responded to your Stack Overflow question here: http://stackoverflow.com/questions/36978449/java-swing-gui-on-kura/36991896#36991896 .

Thanks,
--Dave
Re: GUI swing on OSGI bundle in KURA [message #1731195 is a reply to message #1731111] Tue, 03 May 2016 09:11 Go to previous messageGo to next message
Eclipse UserFriend
David Woodard wrote on Mon, 02 May 2016 21:23
Hello,

I have also responded to your Stack Overflow question here: http://stackoverflow.com/questions/36978449/java-swing-gui-on-kura/36991896#36991896 .

Thanks,
--Dave


Thank you Dave,

(I'm using eurotech's esf)
I put

DISPLAY=localhost:0.0

in /opt/eurotech/esf/bin/start_kura_debug_background.sh and this solve the DISPLAY problem, but now there is another one:

java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit

I think this is a Java problem... or I must pack somethink in my bundle...

I'm using JDK Oracle, not openJDK.
Re: GUI swing on OSGI bundle in KURA [message #1731362 is a reply to message #1731195] Wed, 04 May 2016 12:09 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

Did you verify that the X11 server is running properly? What runlevel is your system starting in? I might recommend starting with runlevel 5 and adding the Kura init.d start script to the rc5 directory.

Thanks,
--Dave
Re: GUI swing on OSGI bundle in KURA [message #1731744 is a reply to message #1731362] Mon, 09 May 2016 14:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
sorry, I'm late, but I was busy with university!
I modify the /etc/inittab, with id:5:initdefault:

Then I control /etc/rc5.d directory and there is S04kura file, so I think the system is ready to run on 5 runlevel.

Next I reboot the system and the who -r result is 5.

The error is
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit

I think there is a library problem.
Re: GUI swing on OSGI bundle in KURA [message #1732497 is a reply to message #1731744] Tue, 17 May 2016 12:52 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

Apologies for the delayed response. I think you are correct, this appears to be a library problem related to XToolkit. I found these two links [1][2], don't know if they are helpful. Have you tried running a simple, plain Java app using XToolkit? This would at least eliminate a possible issue with Kura/OSGi.

[1] https://docs.oracle.com/javase/8/docs/technotes/guides/awt/1.5/xawt.html
[2] http://askubuntu.com/questions/542485/oracle-12c-installation-error-exception-could-not-initialize-class-sun-awt

Thanks,
--Dave

Re: GUI swing on OSGI bundle in KURA [message #1758333 is a reply to message #1731018] Mon, 27 March 2017 14:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi Dave & Folks,

I am trying to display java swing window from an OSGI bundle , deployed to Kura.

I am not finding any exception in Kura. But NO display either.
The Kura thread simply hangs.. as I guess .. as I cant see the Kura log getting populated ...see below...

2017-03-27 23:21:41,148 [pool-25-thread-1] INFO o.s.k.s.p.ManageSensorActions - Showing Image when No one is Around
2017-03-27 23:21:41,416 [MQTT Call: B8:27:EB:52:3D:F6] INFO o.e.k.c.c.CloudServiceImpl - Message arrived on topic: $EDC/retailIOT/B8:27:EB:52:3D:F6/MQTT/APPS
2017-03-27 23:21:41,417 [MQTT Call: B8:27:EB:52:3D:F6] INFO o.e.k.c.c.CloudServiceImpl - Ignoring feedback message from $EDC/retailIOT/B8:27:EB:52:3D:F6/MQTT/APPS
2017-03-27 23:23:08,


in my code :

Activate method to Display image method flow & then



void displayimage(boolean promiximity)
{


/* display frame directly
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("promo.jpg");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
*/
JFrame frame = new JFrame("Hello World");
frame.setSize(640,480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}catch(Exception e)
{
s_logger.info("Exception when showing Image when someone is Near"+e);
}

}
.......

}
}

Re: GUI swing on OSGI bundle in KURA [message #1758386 is a reply to message #1758333] Tue, 28 March 2017 05:45 Go to previous messageGo to next message
Eclipse UserFriend
Additionally when I run the Swing application as a stand alone Java application in Pi , it displays image to the HDMI display correctly......

do I need to do anyother settings...

Amarendra Sahoo wrote on Mon, 27 March 2017 18:33
Hi Dave & Folks,

I am trying to display java swing window from an OSGI bundle , deployed to Kura.

I am not finding any exception in Kura. But NO display either.
The Kura thread simply hangs.. as I guess .. as I cant see the Kura log getting populated ...see below...

2017-03-27 23:21:41,148 [pool-25-thread-1] INFO o.s.k.s.p.ManageSensorActions - Showing Image when No one is Around
2017-03-27 23:21:41,416 [MQTT Call: B8:27:EB:52:3D:F6] INFO o.e.k.c.c.CloudServiceImpl - Message arrived on topic: $EDC/retailIOT/B8:27:EB:52:3D:F6/MQTT/APPS
2017-03-27 23:21:41,417 [MQTT Call: B8:27:EB:52:3D:F6] INFO o.e.k.c.c.CloudServiceImpl - Ignoring feedback message from $EDC/retailIOT/B8:27:EB:52:3D:F6/MQTT/APPS
2017-03-27 23:23:08,


in my code :

Activate method to Display image method flow & then



void displayimage(boolean promiximity)
{


/* display frame directly
JFrame frame = new JFrame();
ImageIcon icon = new ImageIcon("promo.jpg");
JLabel label = new JLabel(icon);
frame.add(label);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
*/
JFrame frame = new JFrame("Hello World");
frame.setSize(640,480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}catch(Exception e)
{
s_logger.info("Exception when showing Image when someone is Near"+e);
}

}
.......

}
}


Re: GUI swing on OSGI bundle in KURA [message #1758574 is a reply to message #1731018] Thu, 30 March 2017 04:48 Go to previous message
Eclipse UserFriend
Hi Ricardo,

I a, trying the same thing, added my swing code in one bundle, and added DISPLAY env variable in KURA startup script, I am not seeing any display.

If you have resloved this ,, can you share your code or some references to it.

regards
Amar
Previous Topic:Kura 1.4 + Moxa Uport 1250
Next Topic:Kura for Virtual Machine
Goto Forum:
  


Current Time: Thu Jul 17 21:25:51 EDT 2025

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

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

Back to the top