Make JButton invisible but clickable?

How to make JButton in java invisible but accessible?

button.setVisible(false); 

makes a button invisible but unattractive, is there any method that makes it invisible but accessible to a click?

I tried to do:

button.setVisible(false);
button.setEnabled(true);

but that didn't work either. I want to do this because I want to have a button with an image, if I put an invisible JButton on top of the image, the button will respond when you click on the image or the invisible button.

+5
source share
2 answers

I think you mean transparency, not invisible.

This will make the button pressed that is not "visible", i.e. transparent:

button.setOpaque(false);
button.setContentAreaFilled(false);
button.setBorderPainted(false);

, , :

ImageIcon myImage = new ImageIcon("images/myImage.jpg");
JButton button = new JButton(myImage);
+19

, , , , JButton , :

class InvisibleButton extends JButton {

    @Override
    public void paint(Graphics g){
          // Do nothing here
    }
}

.

0

All Articles