File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Transparent color for the panel ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Transparent color for the panel !" Watch "Transparent color for the panel !" New topic

Transparent color for the panel !

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577


I have my panel as a rectangle with some data on it. When I point my mouse over that, I should get the color of that panel changed (say a light green color). But, still I need the data present on it visible. How could I achieve this ?

Thanks in advance,

(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Depends on what you're doing. If the data is simple text you can put it on a JLabel and add the JLabel to the JPanel. Add a MouseListener to the JLabel and change the background color of the JPanel in the mouseEntered and mouseExited methods.
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68

Craig saying the right thing. you can use mouseEntered and [I]mouseExited[/I} methods.

in mouseEntered method write -- myPanel.setBackground(; // requried color

in mouseExited method write -- myPanel.setBackground(UIManager.getColor("Panel.background"));
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Thank u guys.

I agree. Here's the link:
subject: Transparent color for the panel !
It's not a secret anymore!