simple questions, hopefully simple answers:

How do i give a JButton the capability to accept a right click?

When a JButton is being clicked it changes to a darker color, is there a way to make it a completely different color?

i cannot find these answers in the API or SUN tutorials, but if you can, a link or sample code would be appreciated.


Right-click is easy to handle

jButton1.addMouseListener(new MouseAdapter(){
    public void mouseClicked(MouseEvent e){
        JOptionPane.showMessageDialog(null,"Right-click stuff");

Changing the button select color is easy if you are wanting to change it for all buttons in your program - even the ones that appear on dialogs and such. For that you can set "" property in the UIManager properties

UIManager.put("", Color.BLUE);

If you want only specific buttons to have the different selected color, you'll have to install your own button UI delegate that extends BasicButtonUI and override the

protected void paintButtonPressed(Graphics g, AbstractButton b)

method and perhaps delegate all other operations to the current look and feel ButtonUI, which may get tricky if you aren't used to pluggable look and feel UI delegation model. There is a complete custom ButtonUI implementation here: if you want to wade through it.

This question has already been answered. Start a new discussion instead.