Search code examples
javaswingtransparencyjbuttonlook-and-feel

transparent JButton when clicked using SystemLookAndFeel


I've prepared transparent Button class:

public MyButton() {

        super("button");
        setOpaque(false);
        setContentAreaFilled(false);
        setBorder(null);
        setBorderPainted(false);
    }

But button is not fully transparent. When it is clicked it looks like this:

enter image description here

Is there any way to avoid this annoying rectangle? There is no such problem in default L&F but I'd like to use SystemLookAndFeel.


Solution

  • You could do

    setFocusPainted(false);
    

    Note: All the above functionality can be achieved by just creating an instance of JButton and using rather than sub-classing the component