Developer community
0 votes
81 views
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).
asked by Guru (24.6k points) 31 57 92 | 81 views

2 Answers

0 votes

 

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
 
 
answered by Expert (13.2k points) 29 44 62
0 votes
 
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);
        }
    });
 
answered by Guru (24.6k points) 31 57 92

Related questions

0 votes
3 answers
asked by john Guru (27.1k points) 35 52 112 | 31 views
0 votes
1 answer
0 votes
1 answer
asked by john Guru (27.1k points) 35 52 112 | 17 views
0 votes
1 answer
asked by keem Expert (13.2k points) 29 44 62 | 26 views
0 votes
1 answer
asked by keem Expert (13.2k points) 29 44 62 | 32 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,754 questions
4,046 answers
117 comments
10,709 users