Why would my buttons paint differently on different systems?

Posted on 2005-05-12
Last Modified: 2010-03-31
Okay, time for another Java newbie question ....

I've got two computers that are quite similar in their setup. Both are running Windows XP Pro SP2. Both of them have the same basic graphics setup (As far as the Windows themes and graphics/performance options). On both, I'm using the same version of Eclipse (3.0.2) with the jdk 1.5.0_03. The odd thing is, when I run a Java app on one system, it will render the buttons with a 'blue to silver to blue' vertical color fade across the buttons. On the other system, it looks more like a standard grey button face. What am I missing? Its the exact same code on both systems.

import java.awt.*;
import javax.swing.*;

public class AppMain
      public static void main(String[] args)
            JFrame win = new JFrame("Yo");
            JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            splitPane.add(new JButton("Left"));
            splitPane.add(new JButton("Right"));
            win.getContentPane().add(splitPane, BorderLayout.CENTER);


So my "Left" and "Right" buttons look different on the two systems. I'm really want to try and garuntee the color faded ones are used, but I have no idea why its rendering like that on one system and not the other. Eh?

Starting value @ 75pts.
Question by:bspotswood
    LVL 14

    Expert Comment

    compare all the values on both system like that:
    on desktop, right mouse button
    appearance tab
    advanced button
    and check the values for all Items

    also here
    rmb on My Computer
    advanced tab
    performance settings button
    check if visual Effect settings are the same

    I hope it helps
    LVL 1

    Author Comment

    Nope, that's what I was talking about above when I said,

    "Both of them have the same basic graphics setup (As far as the Windows themes and graphics/performance options). "

    They're both set the same.
    LVL 6

    Expert Comment

    there mighty also be something wrong with your graphic card, as i don't see your code making the button to look like
    >>'blue to silver to blue' vertical color fade

    I do not even know a look and feel that fades...

    open an simple explorer on both systems and compare there frames..

    LVL 10

    Assisted Solution

    Hi, bspotswood.  Maybe adding code to force a specific LookAndFeel would help?:

    First, add the import statement:
        import javax.swing.UIManager;
    Then, add this in the Main section:
                // Or  UIManager.setLookAndFeel("");
                // Or ...""            
                // Or ..."javax.swing.plaf.metal.MetalLookAndFeel"
            catch (Exception e)
    LVL 1

    Author Comment

    Here's what it looks like on one computer ...

    And here is what it looks like on the other ...

    I guess that's more of a blue to white to blue type fade afterall.

    I added a line into it to see what the look and feel was, but its the same on both systems:


    [The Java(tm) Look and Feel - javax.swing.plaf.metal.MetalLookAndFeel]

    Maybe this isn't as simple of a question as I thought. I'll go ahead and bump the points up to 200.

    I'm rather unfamiliar with the Look and Feel stuff. Maybe there are other options or configuration settings that change the way it behaves? *shrugs* I don't know where to look.

    I may have to end up going with Edward's suggestion and specify something. At least when I use "UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());" then it looks like the WindowsXP theme on both of the systems. Or if I disable the visual styles on the systems it looks like old Windows.
    LVL 14

    Assisted Solution

    javawithcoloring.jpg - in this image the look and feel is the default fot java 1.5.0_03, it's metal L&F
    JavaPlain.jpg - uses some old L&F, I think You should try this on command line:
    java -version
    for both systems. It is possible that MS JVM is used on second one.
    LVL 1

    Author Comment

    On the system the "JavaPlain.jpg" was taken from:

    C:\Documents and Settings\Brent>java -version
    java version "1.5.0_03"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
    Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

    On the sytem the coloring picture was taken from:
    H:\>java -version
    java version "1.3.1_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
    Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

    Ahh ... but but but ... I'm launching Eclipse using the -vm option to specify the Java Virtual Machine being used. Infact, if I don't do this on the system where I'm getting the coloring, then Eclipse won't start up at all because of some missing classes in the 1.3.1 runtime environment. Here is the command I'm using on both systems when launching Eclipse:

    C:\eclipse\eclipse.exe -vm "C:\Program Files\Java\jdk1.5.0_03\bin\javaw"

    Same command line on both systems is being used and both of them are installed the same.

    So in Eclipse, if I open the Help menu -> About Eclipse Platform -> Click the "Configuration Details" button, I see basically the same information. There are a lot of lines, but the ones that are referring to the java VM and runtime being used read the same on both systems: 2 Runtime Environment, Standard Edition
    java.runtime.version=1.5.0_03-b07 Platform API Specification
    java.specification.vendor=Sun Microsystems Inc.
    java.vendor=Sun Microsystems Inc.
    java.version=1.5.0_03 mode, sharing HotSpot(TM) Client VM Virtual Machine Specification
    java.vm.specification.vendor=Sun Microsystems Inc.
    java.vm.vendor=Sun Microsystems Inc.

    So it looks like Eclipse is starting up using the same virtual machine on both systems.
    LVL 14

    Accepted Solution

    Anyway, it looks like the machine with public JRE 1.3.* is using exactly that public JVM and not the 1.5.0)03.
    The only thing to try is to install public JRE 1.5.0_03 instead of 1.3.*
    If this won't help, we'll look further.
    LVL 1

    Author Comment

    Ah hah! Finally an answer that lead me down the right path.

    Maybe its more a problem of me being an Eclipse newbie than just Java? The machine with the 1.3 JRE was the one rendering it with the coloring. It was actually using 1.5.0_3. The machine that wasn't was using JRE 1.4.2. I was loading eclipse with the -vm option to tell it to use 1.5.0_3, but I guess that command only tells it how to load Eclipse and now how Eclipse will compile and run the applications in it? I don't know.

    Anyways, I tried adding the following line to the code so I could see at runtime what version the program was using:


    That's what proved that the program on the machine where it wasn't getting colored right was using some other VM I apparently have installed. I then started digging around in Eclipse to see if this was some sort of configuration option. Sure enough, it was. Along with your project in Eclipse, apparently you can specify the runtime environment to use. I hadn't paid any attention to this before because I really don't know what the hell I'm doing yet.

    Looking at it now though, man was it obvious. Right in the text on the tree node it said "JRE System Library [j2re1.4.2_06]" ... it doesn't get more obvious, right?

    I kept digging and found a way to have it search for my 1.5.0 JRE, it found it, and I set it to use that. With that JRE it looks right.

    Thanks guys, I'll divvy some points up for you and Edward for the help. Thanks for really steering me in the right direction finally, StillUnAware. =)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    Java 1603 Error 2 26
    nested class vs inner class 5 36
    wordsWithout 49 64
    countX 22 49
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now