This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please upgrade to a browser that supports web standards. It's free and painless.

Robert Marcano's blog
Get Firefox Use OpenOffice.org hacker emblem

Java-GNOME

robert | 03 July, 2005 19:30

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

Add comment

 authimage
 
Valid XHTML 1.0 Strict and CSS.
Copyright 2003-2007 Robert Marcano. All Rights Reserved
Powered by LifeType
Original Design by Book of Styles