0

I'm working on a project in university for Java and am using GUI. To make a transparent icon button, I added an image to my button and set button.setContentAreaFilled(false); which works perfectly.

I want the button to be restored to normal when hovered over, and transparent when it's not. Is there any way for me to undo setting ContentAreaFilled to false?

Setting it to true results in what I can only describe as a black outline around the button, why is that? What is its value by default?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Maybe you need to set/unset a few different things: https://stackoverflow.com/a/4586003/74757 – Cᴏʀʏ Jul 15 '20 at 23:43
  • I tried to..but I'm having trouble coming up with an answer – confusedstudent Jul 15 '20 at 23:49
  • I'm not understanding the problem. You added an image to the button. That image will always be painted. What do you expect to see when you hover over the image? Post your [mre] showing the button that is transparent and show another button demonstrating what you mean by normal? – camickr Jul 16 '20 at 00:29
  • I found some sample code that you might be able to tweak: https://stackoverflow.com/a/22639355/74757. It uses a custom button implementation and some hover effects. You could drop the for-loops in the mouse-entered and mouse-exited methods and directly set the opacity to 1f or 0f. – Cᴏʀʏ Jul 16 '20 at 00:30
  • Is it possible for you to capture the current values for the desired fields before you make your transition? Then, you set everything back to their initial values when you want things to be restored to normal? – Xaero Degreaz Jul 16 '20 at 00:36
  • 1
    You might swap between a transparent and non-transparent image between normal and mouse over. .. If I understand the problem, which I'm almost certain I don't. General tips: 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. [This answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson Jul 16 '20 at 01:16
  • 1
    .. by 'mouse over' I mean [`setRolloverIcon(javax.swing.Icon)`](https://docs.oracle.com/en/java/javase/13/docs/api/java.desktop/javax/swing/AbstractButton.html#setRolloverIcon(javax.swing.Icon)). – Andrew Thompson Jul 16 '20 at 01:19
  • Thank you @Cᴏʀʏ!! It worked! Thanks for the help everyone! – confusedstudent Jul 16 '20 at 01:33

0 Answers0