You are not logged in.

#1 2004-11-19 22:03:00

LB06
Member
From: The Netherlands
Registered: 2003-10-29
Posts: 435

[java] Look & Feel in xfce4

import javax.swing.*;



public class WindowUtilities {


    public static void setNativeLookAndFeel() {

        try {

            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        }
        catch(Exception e) {

            System.out.println("Error setting native LAF: " + e);

        }

    }



    public static void setJavaLookAndFeel() {

        try {

            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

        }
        catch(Exception e) {

            System.out.println("Error setting Java LAF: " + e);

        }

    }



    public static void setMotifLookAndFeel() {

        try {

            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

        }
        catch(Exception e) {

            System.out.println("Error setting Motif LAF: " + e);

        }

    }

}
        WindowUtilities.setNativeLookAndFeel();

I am using this class to set the Java Look & Feel of my program. Basically I have three options: Motif, native(GTK2/Win32/OSX), or Metal(Steel/Ocean). But when I set it to native in xfce4, it is set to Java look and feel, whatever I do. In Gnome, however, I get a nice GTK2 look and feel with the current GTK2 theme I'm using in Gnome.

Does anyone know how to make java use to gtk2 in xfce4? Btw no exeption is thrown.

Offline

#2 2004-11-20 11:50:26

zeppelin
Member
From: Athens, Greece
Registered: 2004-03-05
Posts: 807
Website

Re: [java] Look & Feel in xfce4

I did a bit of search, didn't find much sorry.
as always java docs are way too informative
http://java.sun.com/j2se/1.4.2/docs/api … lassName()

it doesn't say how it gets it!!

my guess is it looks for a $VARIABLE
if I were you I would do in GNOME

set > gnome-vars.txt
then in XFCE4
set > xfce4-vars.txt
and diff them

(visualize diff):
pacman -S meld
meld&
and open to diff those files.

good luck [see for gtk/gnome specific vars that should be in GNOME and not in xfce4]
when you find one, export it, and rerun your java app.
hopefully you will find which one is it.

then in your code, you can set this variable to what it's needed for java's idiotic UIManager do force to use gtk look.

of course there are other ways to do that, maybe check for $GTK_RC_FILES, and if they are there then my guess is that this is Unix and has Gtk so force gtk look etc..

or you can look at java's source to find the answer on what is looks for to determine the look. wink
or you can ask here and even better in java+linux forums

[flame on]
Programming is fun, not with JAVA though.
[/flame off]

Offline

#3 2004-11-20 22:51:18

LB06
Member
From: The Netherlands
Registered: 2003-10-29
Posts: 435

Re: [java] Look & Feel in xfce4

Hmm, well my intention is that my app gets a native look on gtk, win9x, winxp and macos(x?), with as less hassle as possible. Meaning, it would be highly preferrable to be able to force the look in the app,  not in the system. Then again, I do not want my app to look like a gtk one in Windows (or vice versa).

Perhaps I should switch to wxpython or something. I only chose Java because we have to code in Java at my uni and I thought it would be easy to write native looking apps for linux and windows. Besides that, my java skills are better than my python skills. Btw I do not wish to use swt.

Does anyone know a simple way to handle laf in java or a good cross-platform and relatively easy to learn toolkit?

Offline

#4 2006-01-22 16:50:00

iLLucionist
Member
From: Groningen, Netherlands
Registered: 2005-09-09
Posts: 18

Re: [java] Look & Feel in xfce4

Yeah, use SWT to do the job. It renders the proper UI for win32/winXP, OS-X (Carbon), Motif, CDE, Photon aanddd, last but not least, gnome.

Here you are: http://www.eclipse.org/swt/.

Oh, and btw. about tutorials? Here you are:
:arrow: SWT Snippets
:arrow: Getting started with Eclipse and the SWT

Have fun. 8)


L. M. Laurijssen

-- Simplicity is the highest level of complexity.

Offline

#5 2006-01-22 17:14:09

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: [java] Look & Feel in xfce4

talk about thread revival...

Offline

#6 2006-01-22 17:17:48

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: [java] Look & Feel in xfce4

SWT quite possible the best toolkit to use to match the native laf, as iLLucionist said. However, there's a lot of extra learning to do, and there's a lot more hassling with shipping native libs for each platform you're releasing for, etc, etc.

It's also worth pointing out the the gtk laf in Java 1.5 is really, really crap. The default cross-platform laf, Ocean, is hardly good looking either, but the gtk laf is poooor! Why is that? Well, in 1.5, Java Swing shipped with a generical LAF kit called Synth. The idea of this is to avoid the usual, complicated, route of writing your LAF by writing all your own delegates for all the components. Instead, Synth is a system for essentially defining 'skins'. Not a lot happened with it in time for the 1.5 release though. It wasn't documented much and it had bugs. However, that didn't stop Sun shipping their gtk laf as a Synth theme. It was obviously not the most advanced implemention of gtk, as you can see for yourself.

That's not to say that Synth is a poor concept - it can be made to produce some great stuff (see Synthetica demo and Romain Guy's work).

Anyway, the next version of Java has good news when it comes to interface fidelity (i.e., does the laf look like a native app). The Windows Laf already uses native functions to render some of the components, but there's more of that to come. And most importantly, the gtk laf also implements native calls to gtk - so things should look much more "native" in the next release. A good (but already out-of-date) review can be seen here.

However, I'm sure you need a solution "now"(-ish). One approach that I'd advocate is that if native laf is not absolutely required, that you look for one of the high quality lafs that look great on any platform. I'd recommend JGoodies looks. Sun has been so impressed with JGoodies looks that I understand they sponsor the developer to help them improve their own lafs.

I'd personally love to have the Imagery LAF. It's actually now available via the JIDE libraries (which is a commercial kit).

Offline

#7 2006-01-22 17:19:41

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: [java] Look & Feel in xfce4

Dusty wrote:

talk about thread revival...

Hell yeah - it's been happening a lot recently. Unfortunately, I didn't realise just how old this thread was until I posted my previous reply. D'oh!

Offline

#8 2006-01-22 17:35:26

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: [java] Look & Feel in xfce4

You should have been able to tell from the fact that zepplin was still posting here. He got fed up at least a year ago...

Dusty

Offline

#9 2006-01-22 17:37:48

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: [java] Look & Feel in xfce4

But I ain't as wise as you!

Offline

Board footer

Powered by FluxBB