Now that many Linux distributions are packaging updated versions of GCJ, Eclipse and Java-GNOME, never has been so easy to develop GNOME applications using Java. I am using Fedora Core 4 and for this little tutorial you must have installed:
- eclipse-jdt
- libgtk-java
- libgnome-java
- libgconf-java
- libglade-java
You can use yum to install them:
yum install eclipse-jdt libgnome-java libgconf-java libglade-java libgtk-java
Start Eclipse and create a Java project. Edit the build path of your new project adding the following external jars
- /usr/share/java/gtk2.6.jar
- /usr/share/java/gconf2.10.jar
- /usr/share/java/glade2.10.jar
- /usr/share/java/gnome2.10.jar

Now you can try with this example:
public static void main(String[] args) {
// intializing GTK
Gtk.init(args);
// creating the widget tree
Window window = new Window(WindowType.TOPLEVEL);
window.setTitle("Testing GTK");
window.add(new Button("Test..."));
// adding a listener to detect when the window is closed to end the
// event dispatch main cycle and exit the application
window.addListener(new LifeCycleListener() {
public void lifeCycleEvent(LifeCycleEvent evnt) {
if (evnt.getType() == LifeCycleEvent.Type.UNREALIZE)
Gtk.mainQuit();
}
public boolean lifeCycleQuery(LifeCycleEvent evnt) {
return false;
}
});
// showing the window
window.showAll();
// starting the event dispatch cycle
Gtk.main();
}
Test the application and you will get something like this:

Extended documentation can be found on the Java-GNOME documentation page and the original GNOME documentation (C based APIs)










Comments (0) |
Trackbacks (0)