0

I am trying to create a undecorated JFrame, but I am having some issues with my Closing button, It has this ugly "selected" border around it, is there any way of removing it? (Top right corner of image)

This button

This is what I did to remove all borders and backgrounds:

JButton btnX = new JButton("");
    btnX.setIcon(new ImageIcon(GameHubMain.class.getResource("/Resources/Close-icon.png")));
    btnX.setForeground(Color.WHITE);
    btnX.setOpaque(false);
    btnX.setContentAreaFilled(false);
    btnX.setBorderPainted(false);
    btnX.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            frame.dispose();
        }
    });
Sander_Blaadjes
  • 159
  • 1
  • 1
  • 10

2 Answers2

2

Maybe try this ?

Border emptyBorder = BorderFactory.createEmptyBorder();
btnX.setBorder(emptyBorder);

You should also try adding:

btnX.setFocusPainted(false);
btnX.setMargin(new Insets(0, 0, 0, 0));
dehlen
  • 7,325
  • 4
  • 43
  • 71
  • The exact same answer: http://stackoverflow.com/questions/2713190/how-to-remove-border-around-buttons – DeiAndrei Feb 19 '15 at 09:48
  • well because I didn't searched stackoverflow before posting my answer. Looks like someone had the idea before me. EDIT: also added some additional stuff that could help the OP. – dehlen Feb 19 '15 at 09:50
1

Add following line in your code and check

btnX.setBorder(BorderFactory.createEmptyBorder());
Kunal Surana
  • 659
  • 5
  • 14