?
Solved

JAVA JButton not transparent when clciked Weird ????

Posted on 2003-12-06
9
Medium Priority
?
488 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
[X]
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
9 Comments
 
LVL 86

Expert Comment

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

Author Comment

by:jacquesdr
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"));
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
ID: 9888021
You should maybe set the pressed icon. Can you post that gif somewhere public?
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

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


0
 
LVL 86

Expert Comment

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

Author Comment

by:jacquesdr
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 ???

0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 9889870
button.setContentAreaFilled(false);
0
 

Author Comment

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

Expert Comment

by:objects
ID: 9891481
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

770 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