Results 1 to 9 of 9
Hello! I'm trying to build a GUI for my java app and compile with gcj (to native code). I started googling and found 3 possibilities: Java-Gnome, Gnome-GCJ and libswt. Unfortunately, ...
- 07-02-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 8
Java and GTK (native code)
Hello! I'm trying to build a GUI for my java app and compile with gcj (to native code). I started googling and found 3 possibilities: Java-Gnome, Gnome-GCJ and libswt. Unfortunately, Java-Gnome is not compatible with gcj and Gnome-GCJ is, but is no longer maintained. The third option, libswt, I could not find any clear information what is it and how it works. Can you enlighten me a bit more about the subject?
- 07-03-2010 #2
So I don't know anything about using it with gcj, but I've used SWT before. It's basically a GUI toolkit developed by the Eclipse Foundation, and it is what Eclipse uses. I originally came to it because it uses native libraries for its graphics, and it looked a lot nicer than Swing back in the day (this was when Swing on Linux looked like Gtk 1.x, which is really ugly).
The SWT page is at:
SWT: The Standard Widget Toolkit
You may also want to look at JFace, which I've never used, but supposedly makes using SWT easier:
JFace - EclipsepediaDISTRO=Arch
Registered Linux User #388732
- 07-03-2010 #3Just Joined!
- Join Date
- May 2010
- Posts
- 8
I was talking about libswt dot sourceforge dot net
Anyway, same principles probably are applied for both swt's. Anyone having experience with gcj compiling this?
- 07-04-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Some indication of the errors you are getting might be helpful...
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-04-2010 #5
I'm with Rubberman: clarification of your errors would help. Assuming that you've written your Java code with SWT, it should be as simple as passing -lswt to the linker in order to make it work with libswt.so, as you would do with any shared library.
DISTRO=Arch
Registered Linux User #388732
- 07-04-2010 #6Just Joined!
- Join Date
- May 2010
- Posts
- 8
Actually, I don't know from where to start at all. I will try reading the eclipse's manual of how to build an app, but would the code be compatible with libswt? Also, what do I have to pass to gcj to detect the needed shared objects (probably some classpath option, but I never did that before)?
I'm sorry for being so unhelpful, but I never done something like that before and I'm still disoriented what to do.
- 07-05-2010 #7Just Joined!
- Join Date
- May 2010
- Posts
- 8
I made some progress, now I have an error

Here is the sample code:
In order to compile it, I run: (found on the net)Code:import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; public class Snippet143 { public static void main(String[] args) { Display display = new Display (); Shell shell = new Shell (display); Image image = new Image (display, 16, 16); final Tray tray = display.getSystemTray (); if (tray == null) { System.out.println ("The system tray is not available"); } else { final TrayItem item = new TrayItem (tray, SWT.NONE); item.setToolTipText("SWT TrayItem"); item.addListener (SWT.Show, new Listener () { public void handleEvent (Event event) { System.out.println("show"); } }); item.addListener (SWT.Hide, new Listener () { public void handleEvent (Event event) { System.out.println("hide"); } }); item.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { System.out.println("selection"); } }); item.addListener (SWT.DefaultSelection, new Listener () { public void handleEvent (Event event) { System.out.println("default selection"); } }); final Menu menu = new Menu (shell, SWT.POP_UP); for (int i = 0; i < 8; i++) { MenuItem mi = new MenuItem (menu, SWT.PUSH); mi.setText ("Item" + i); mi.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { System.out.println("selection " + event.widget); } }); if (i == 0) menu.setDefaultItem(mi); } item.addListener (SWT.MenuDetect, new Listener () { public void handleEvent (Event event) { menu.setVisible (true); } }); item.setImage (image); } shell.setBounds(50, 50, 300, 200); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } image.dispose (); display.dispose (); } }
And I got when trying yo finally run it:Code:gcj -fjni --classpath=/usr/share/java/swt.jar -c Snippet143.java -o Snippet143.o gcj -fjni -c /usr/share/java/swt.jar gcj -shared -fPIC -fjni -o libswt.o swt.o -o libswt.so gcj --main=Snippet143 -o Snippet143 Snippet143.o -L. -lswt
Code:error while loading shared libraries: libswt.so: cannot open shared object file: No such file or directory
- 07-05-2010 #8Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
It's saying that it can't find the shared library file libswt.so.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-05-2010 #9Just Joined!
- Join Date
- May 2010
- Posts
- 8
I found that file: /usr/lib/gcj/swt-gtk-3.5.1.jar.so
It's probably the one I would like to link to instead of making my own libswt.so file. What to change in the compile commands to do it?
Edit: Wrong file. Seems it's not to be working. Is there some package that is providing libswt.so? (or else I should move it to lib)


Reply With Quote