Creating a custom button in Java with JButton

后端 未结 4 1808
陌清茗
陌清茗 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 12:01

    try a Jlabel and use an image for any shape!!

        JLabel lbl = new JLabel("");
        lbl.setIcon(new ImageIcon("shape.png"));
        lbl.setBounds(548, 11, 66, 20);
        contentPane.add(lbl);
    
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                System.exit(0);
            }
        });
    

提交回复
热议问题