• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Why would my buttons paint differently on different systems?

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.
3 Solutions
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
bspotswoodAuthor Commented:
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.
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..

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            // Or ..."com.sun.java.swing.plaf.gtk.GTKLookAndFeel"            
            // Or ..."javax.swing.plaf.metal.MetalLookAndFeel"
        catch (Exception e)
bspotswoodAuthor Commented:
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.
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.
bspotswoodAuthor Commented:
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:

java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.vendor=Sun Microsystems Inc.
java.vm.info=mixed mode, sharing
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java 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.
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.
bspotswoodAuthor Commented:
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. =)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now