I have this code to make Jbutton with an icon image and it works. But the problem is that the borders and background of the button do not disappear.
I want only the icon image to display without borders and button background.
I tried to set setOpaque(false) , but the whole button disappeared!
What happened in my code?
_button = new JButton("Exit"); _button.setHorizontalTextPosition(SwingConstants.CENTER); _button.setSize(200,130); //_button.setContentAreaFilled(false); _button.setBorderPainted(false); //_button.setOpaque(false); _button.setIgnoreRepaint(true); //_button.setFocusable(false); _button.setIcon(button_icon); _button.setBounds(200, 200,200, 170); _button.setRolloverEnabled(true); _button.setRolloverIcon(button_icon_hover); _button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); //_button.addActionListener(this); _button.setBackground(null); _button.setFocusable(true); _button.setFocusPainted(true); _button.setForeground(Color.WHITE); _button.setFont(new Font("Times New Roman",Font.BOLD,35));
source share