Solace
Solace

Reputation: 9020

Java Swing - How to make the JButton's boundaries invisible?

In the screenshot below, you can see four buttons in the selected area. I want to mimic this kind of buttons in my GUI application. Each of these buttons has an image on them (play,stop, forward, rewind). I can use the icon property of the button to add an image to it.

When the user hovers the mouse pointer over a button, three things happen:

  1. it changes color- I don't need this feature.
  2. It displays a tool tip. I know how to do it by using the tooltip text property of a button.
  3. Most importantly, these buttons don't have a border around them, That is their bounds are not visible at all. It's just the image which is visible. I want to do something like this. But when I add an image to a button, its border does not go away (I mean it's bounds are clearly visible in the form of a line - as you can see in the second image)

So what property of an button should I manipulate, or what method should I use, to make its borders (and every visible trace of the button except the image present on it) invisible?

enter image description here

enter image description here

Upvotes: 0

Views: 1025

Answers (1)

Nivas
Nivas

Reputation: 18364

A border is painted when setBorderPainted is set to true, otherwise not:

setBorderPainted:

Sets the borderPainted property. If true and the button has a border, the border is painted. The default value for the borderPainted property is true. Some look and feels might not support the borderPainted property, in which case they ignore this.

Note that some look and feels may ignore this property.

Update:

The default look and feel is called CrossPlatformLookAndFeel. This is not a look and feel but an indicator of the default one. What you get as default depends on the platform you are using. See How to Set the Look and Feel for details. I personally loke the Nimbus Look and Feel, but I have encountered some problems with it. I am not sure if it respects setBorderPainted, but I will not be surprised if it does not.

Upvotes: 4

Related Questions