Making a JButton invisible, but clickable?

前端 未结 2 1109
小鲜肉
小鲜肉 2021-01-02 17:23

How do I make a JButton in java, invisible, but clickable?

button.setVisible(false); 

makes the button invisible, but unclickable, is there

2条回答
  •  鱼传尺愫
    2021-01-02 17:37

    I think you mean transparent, rather than invisible.

    This will make a clickable button that is not "visible", i.e. transparent:

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

    This answers your asked question, but if your intent is to make an image clickable, there is a better way for that, too:

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

提交回复
热议问题