Search code examples
javaswingfocusborderjbutton

How do i get rid of a blue border surrounding my button? For Java GUI


Because it wont let me add an image - new account

Monster

This is utilizing the Java GUI The above image is an image pasted onto a button, I've tried to make the button transparent so that the user can't see it but I can't seem to get rid of this blue border. Code I have so far

    boss2 = new JButton();    //declared the static button earlier on in the code

    boss2.setSize(300, 300);
    boss2.setLocation(315, 200);
    boss2.setIcon(new ImageIcon("dragon.gif"));
    boss2.setRolloverIcon(new ImageIcon("dragon.gif"));
    boss2.setOpaque(false);
    boss2.setContentAreaFilled(false);
    boss2.setBorder(null);

Is there a way to get rid of the blue border surrounding my image?

edit - sorry for the earlier mishap, uploaded the wrong file


Solution

  • I would suggest that what you are seeing is the focus rectangle, used to "highlight" the button as having keyboard focus.

    You can use boss2.setFocusPainted(false); to stop it from been painted.