JAVA JButton not transparent when clciked Weird ????

Posted on 2003-12-06
Last Modified: 2008-03-06
Hi i'm coding a smaal java app, adn my problem is i have a JFrame to that i had a JPanel and to that a JButton with a ImageIcon

All is well and it display the button with the transparent image but when i click it it ( when the mouse is down on the button it turns into gray  ??\how do i fix this ?
thank you

Question by:jacquesdr
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
  • 4
  • 3
  • 2
LVL 86

Expert Comment

ID: 9887985
You should set the icons for the various button states if necessary. See the following methods of AbstractButton (the superclass)

 void setDisabledIcon(Icon disabledIcon)
 void setDisabledSelectedIcon(Icon disabledSelectedIcon)
 void setIcon(Icon defaultIcon)
 void setPressedIcon(Icon pressedIcon)
 void setRolloverIcon(Icon rolloverIcon)
 void setSelectedIcon(Icon selectedIcon)

Author Comment

ID: 9888003
but it's the who;e button i don't think it has todo with the icon when i press the button it's gray when i releases it it fine again

small test app
public class t extends JFrame
 private Color purple                = new Color(100,102,156);
 JLabel l = new JLabel("22.gif");
 JButton b = new JButton("www," ,new ImageIcon("22.gif"));





      setVisible( true);

public static void main(String[] args)
       new t ();

LVL 86

Expert Comment

ID: 9888021
You should maybe set the pressed icon. Can you post that gif somewhere public?
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 9888035
Well i set the pressed Icon property - no diffrence
the gif is transparent the gif is not the problem !

LVL 86

Expert Comment

ID: 9888078
Yes, i understand what you mean now. The default behaviour of a button is to turn down when pressed and is indeed nothing to do with the icon. What do you want to happen?

Author Comment

ID: 9889635
Sorry man was at work ;)
Well i want it to be still purple(transparent) i'll just maby then need to use labels instead ???

LVL 92

Accepted Solution

objects earned 500 total points
ID: 9889870

Author Comment

ID: 9891477
Thank you very much !!!
it's great ! ;)
LVL 92

Expert Comment

ID: 9891481

Featured Post

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!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

724 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