I have this code to make a Jbutton with icon image ,and it works.But the problem is that the borders and background of button don't disappear.
I want only the icon image is appear without borders & background of button.
I tried to set setOpaque(false)
, but all of button disappeared!
What is the wrong 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));
JButton can become transparentIf the value of the opaque property of a JButton is set to false, the background becomes transparent allowing whatever is behind the button to show through. Only the text and the border of the button remain opaque.
Simple, Set the icon to null . It doesn't have an icon, so it removes it. That will work perfectly.
In Visual Studio with Windows Forms a ToolStrip has TabStop set to false by default. Use my UI fix above to get rid of the dotted borders on Toolbar buttons and ToggleButtons which never have them in Windows with or without focus.
you can use this code: Icon i=new ImageIcon("image. jpg"); jButton1. setIcon(i);
Try this
JButton play = new JButton("This",new ImageIcon("src\play.png"));
play.setBorderPainted(false);
play.setContentAreaFilled(false);
play.setFocusPainted(false);
play.setOpaque(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With