Making a JButton invisible, but clickable?

前端 未结 2 1110
小鲜肉
小鲜肉 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:40

    Well, there is no point so since there is no point there is no standard way to do this, but it's possible to override the paint method of JButton and do nothing in it like:

    class InvisibleButton extends JButton {
    
        @Override
        public void paint(Graphics g){
              // Do nothing here
        }
    }
    

    Try playing around with this.

提交回复
热议问题