Results 1 to 10 of 18

Thread: Making Java GUI's look good

Hybrid View

  1. #1
    Join Date
    Jul 2008
    Beans
    7

    Making Java GUI's look good

    I was asked to start a new thread on this question, which I posed elsewhere: Why does my Java GUI stuff look so poor on Linux? I am using native Look and Feel, which works fine in Win XP and Vista, but in Java it seems to not paint properly.

    I am hoping that someone who has had some experience with this may recognize this as a familiar problem. I don't mean for this to be a discussion of how to subclass JButton, or what-not. I just mean that if I take a .jar file that looks good elsewhere, what might be happening (what might I have forgotten?) that would render that Linux version poorly?

    For example, when I install (apt-get) Netbeans, it also installed Java. Sun's Java? How can I be sure? If not, that may explain it.

    Or perhaps the problem lies elsewhere. (I'm fairly new to Linux, and very new to Ubuntu....)

    Anyway, I'd love to hear (read) ideas on this. Thanks!

  2. #2
    Join Date
    Jul 2008
    Location
    Athens, Georgia
    Beans
    228

    Re: Making Java GUI's look good

    I'm not sure exactly what you're seeing, but different versions of Java WILL look different. I use Java on all of my machines. I have an old machine that I installed Xubuntu on, and I installed GNU's java compiler. It worked fine, but did look kind of cheap. I later put a new hard drive in and reinstalled Xubuntu. This time I installed Sun's java. Still doesn't have the look of a Windows GUI, but it DOES look different from the GNU version. I have Netbeans recently installed on this (Ubuntu) machine, but I haven't played with it yet so i don't know what this implementation looks like. I am familiar with Netbeans from my Windows use, but I use the command line and VIM editor for Java programming on my old machine. Hold on....

    OK it DOESN'T look like the Netbeans install grabs the Sun java packages - it is a hodgepodge of stuff, some of which is from GNU. That could explain it. You can check yourself by opening Synaptic Package Manager, searching for "java", then looking to see which packages are installed.

  3. #3
    Join Date
    Apr 2005
    Location
    Glasgow, Scotland
    Beans
    1,642

    Re: Making Java GUI's look good

    Java's "GTK+" theming is crap. It'd be better to just use good old Metal.
    A Fedora user

  4. #4
    Join Date
    Jul 2008
    Location
    Athens, Georgia
    Beans
    228

    Re: Making Java GUI's look good

    Yeah - I believe the "Metal" theme is the IcedTea default......

  5. #5
    Join Date
    Jul 2008
    Beans
    7

    Re: Making Java GUI's look good

    Thank you, HotCupOfJava. The Synaptic Package Manager says that the sun-java6-jdk is not installed. Thus, I'm probably using OpenJava (or whatever that was called).

  6. #6
    Join Date
    Apr 2005
    Location
    Glasgow, Scotland
    Beans
    1,642

    Re: Making Java GUI's look good

    Quote Originally Posted by dhimes View Post
    Thank you, HotCupOfJava. The Synaptic Package Manager says that the sun-java6-jdk is not installed. Thus, I'm probably using OpenJava (or whatever that was called).
    No, that's the old non-free Java 1.6. openjdk-6-* is the OpenJDK one.

    Quote Originally Posted by HotCupOfJava View Post
    Yeah - I believe the "Metal" theme is the IcedTea default......
    It's Java's native LaF.
    A Fedora user

  7. #7
    Join Date
    Jul 2008
    Beans
    7

    Re: Making Java GUI's look good

    So, is openjdk-6-jre Sun's version? I thought they just open-sourced what they had.

  8. #8
    Join Date
    Apr 2005
    Location
    Glasgow, Scotland
    Beans
    1,642

    Re: Making Java GUI's look good

    Quote Originally Posted by dhimes View Post
    So, is openjdk-6-jre Sun's version? I thought they just open-sourced what they had.
    Suprisingly, no. I think it's a forked version of Sun's OpenJDK with the non-free bits replaced.

    OpenJDK when released had about 95% source available, meaning the other 5 had to be replaced.
    A Fedora user

  9. #9
    Join Date
    Jul 2008
    Location
    Athens, Georgia
    Beans
    228

    Re: Making Java GUI's look good

    Yeah - I guess what I should have said was "Metal is the original, and thats what IcedTea uses"......But hey - I've never paid close attention to the GUI themes - I'm just glad the code works.

  10. #10
    Join Date
    Nov 2007
    Location
    New Zealand
    Beans
    1,026
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Making Java GUI's look good

    I've been happy with the Sun JRE version.

    The following command will tell you for sure what JRE you are using.

    Code:
    java -version
    You may have multiple JRE's on your machine, if this is the case then synaptic package manager may tell you that you have the Sun JRE installed but you will not actually be using it when you invoke the "java" command. The above java version command will tell you what JRE you are using.

    Also, there are three things you can do to get Java GUI's looking better without too much work.

    1. Using the "native look and feel".
    2. Create your own base JPanel class and enable antialiasing.

    Code:
    public class JBasePanel extends JPanel {
        @Override
        public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        }
    }
    All panels you create should extend this.

    3. Manually set your fonts to something sensible like arial.

    There are a lot of other things you can do, the above tips are just the easy ones.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •