background for button

Posted on 1997-05-03
Last Modified: 2010-04-16
I have an applet that has buttons that change color depending on the situation.  This applet works fine
on a unix machine. However, on a pc this doesnt work.
So much for paltform independent.  Is there a way
to make this work on a pc?

Here are parts of the code:

 if (dates[0]  != null) {
              for(int k=0;k<dates.length;k++)
                  if(!(month==null) && changeMonth(month)==thismonth && Integer.parseInt(dates[k][3])==tmp && Integer.parseInt(dates[k][4])==thisyear+1900)
                      myButton[i].setBackground(new Color(0, 128, 128));
          else myButton[i].setBackground(new Color(16512));    
Question by:arth
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1220085
Could you post the relevant parts of the code?

Author Comment

ID: 1220086
Edited text of question

Expert Comment

ID: 1220087

Have you tried:

myButton[i].setBackground(new Color(0, 128, 128));

To force an update of the component?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1220088
Maybe this is an answer, but one you won't want! I think in the windows implementation, background has no effect (ie if you could change background it would be for all gui buttons). Not 100% on this though.If this is the case, your only alternative is to code up your own button class, or perhaps just use a bitmap type button from somewhere.

Expert Comment

ID: 1220089
Sorry you rejected my answer, but I have discovered it's true. Maybe in 1.1.? they will introduce some trick to accomplish it. I had someone else run into this (with a code sample from a book) and it does run on unix but not in win95 (didn't try any others).So unless you use an alternative button you make yourself, I think you're stuck for now....

Accepted Solution

jpzwarte earned 100 total points
ID: 1220090
I don't know if it works with setBackground, but i've used it succesfully with setForeground in jdk1.1.1. ... i just tried using setBackground on a button in jdk1.1.1 and it WORKS!

here's some code:

public void mouseEntered(MouseEvent e)
        Object obj = e.getSource();
        Color active =;

        if (obj == Quit) // Quit = Button
            Quit.setBackground(active); // this WORKS!
        else if (obj == Send)
        else if (obj == SendToAll)
        else if (obj == ClearText)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to install java on RHEL image on EC2 4 53
ejb entity bean example issue 2 25
Notify sent to other threads in Java 9 41
running on tomcat not jboss eap 7.0 3 28
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

735 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