Creating a custom button in Java with JButton

后端 未结 4 1870
陌清茗
陌清茗 2020-11-21 11:38

I am trying to create a button that has a custom shape (hexagon), but otherwise acts like a normal JButton would (that is, works with an ActionListener).

I have crea

4条回答
  •  迷失自我
    2020-11-21 11:58

    You will have to extend JButton class not AbstractButton. Try the following things and you will get idea.

    The first move is to subclass JButton.

    Then, in your subclass, start by redefining the paintComponent(Graphics) method. If you want any changes.

    Then, override paintBorder(Graphics) to give it a shape of hexagon.

提交回复
热议问题