Solved

JAVA JButton not transparent when clciked Weird ????

Posted on 2003-12-06
9
440 Views
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

0
Comment
Question by:jacquesdr
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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)
0
 

Author Comment

by:jacquesdr
Comment Utility
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"));
t()

{
   b.setOpaque(false);

   getContentPane().setLayout(null);
      getContentPane().setBackground(purple);

      b.setBounds(10,10,100,100);
      getContentPane().add(b);

      setSize(800,600);
          setResizable(false);
            this.setLocation(100,100);

      setVisible( true);
}


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

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You should maybe set the pressed icon. Can you post that gif somewhere public?
0
 

Author Comment

by:jacquesdr
Comment Utility
Well i set the pressed Icon property - no diffrence
the gif is transparent the gif is not the problem !


0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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?
0
 

Author Comment

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

0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
button.setContentAreaFilled(false);
0
 

Author Comment

by:jacquesdr
Comment Utility
Thank you very much !!!
it's great ! ;)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars2 challenge 6 66
powerN  challenge 3 46
changeXy challenge 13 56
return in catch statement 1 39
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

763 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

6 Experts available now in Live!

Get 1:1 Help Now