Tuesday, 3 August 2010

Java and Gnome

I don't often write GUI applications but I have been experimenting over the last few days with the Java-Gnome User Interface Library for writing Gnome-based applications in Java.

The disadvantage of this of course is that you forego the "write-once-run-anywhere" ethos behind Java; the finished application will only run on a system that uses Gnome as its window manager. The standard, cross-platform way of doing things is to use Swing but the "native" look & feel widgets are only imitations of the real thing and, Windows aside, can look like poor imitations.

Compare these screenshots for example, of a colour chooser dialog in Swing on a Gnome desktop (Ubuntu 10.04) and a native Gnome application:

I suppose the best compromise would be to use the Standard Widget Toolkit (SWT), as used by the Eclipse platform, which is a standard interface underpinned by native windowing system widgets.

The Java Gnome User Interface Library

Subject to the above caveats, my first impressions of the Java-Gnome UI Library is very good. I don't think all of GTK is covered as yet, but there is certainly enough there to write perfectly serviceable applications for Gnome desktops. As an exercise, I managed to knock together a perfectly serviceable text editor in a couple of days, complete with syntax highlighting, cut/copy/paste, undo/redo, open/save dialogs and shortcut keys.

I found the code quite simple to write and was up and running quite quickly. Creating things like menus and toolbars is made very easy with the concept of actions, and standard framework actions (stock actions) keep things consistent. Handling events is straightforward when you have written a couple of event handlers. The trickiest part was getting round a few subtleties of the undo/redo mechanism, which kept crashing the application because I didn't understand it properly. But rock solid now.

As with any GUI framework, code can get into a mess very quickly, so some organisation is essential. The approach I used on the editor exercise was to make the main application window a subclass of the Window class, set it up as a singleton and have it create the other components it needed in its constructor. Any code in the components can then look up the singleton instance and access methods and data in the other components in a controlled way.

There is an excellent tutorial available to get started and the API documentation is very good.

Well worth a try if you want to write some applications for the Gnome desktop in Java.

7 comments:

JAHAN said...


When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.

AWS Training in Bangalore | Amazon Web Services Training in Bangalore

Amazon Web Services Training in Pune | Best AWS Training in Pune

AWS Online Training | Online AWS Certification Course - Gangboard

genga g said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.

angularjs-Training in velachery

angularjs-Training in annanagar

angularjs Training in chennai

angularjs Training in chennai

mouni yoga said...

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
Python training in marathahalli | Python training institute in pune

saranya p said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
advanced excel training in bangalore

jeeva said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

blueprism training in chennai | blueprism training in bangalore | blueprism training in pune | blueprism online training

sudhagar raja said...

Impressive. Your story always bring hope and new energy. Keep up the good work.
Java training in Chennai | Java training in Bangalore

Java interview questions and answers | Core Java interview questions and answers

shalinipriya said...

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

Data Science Training in Chennai | Data Science training in anna nagar

Data Science training in chennai | Data science training in Bangalore

Data Science training in marathahalli | Data Science training in btm layout

Followers