1

Is there a way to remove the rectangular border under the button?

I wish to make it transparent, is it possible?

Here is the image:

enter image description here

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Francesco Rizzi
  • 631
  • 6
  • 24
  • 2
    See [Removing space around buttons in GridBagLayout](http://stackoverflow.com/q/32540954/418556) for ways to make buttons (effectively) invisible. – Andrew Thompson Sep 19 '15 at 08:27

2 Answers2

3

You can use this code segment, where b is the instance of your JButton.

For only remove rectangular border just use

 b.setBorderPainted(false);

To make button transparent:

b.setOpaque(false);
b.setContentAreaFilled(false);
b.setBorderPainted(false);

Also remove Painted focus add this

b.setFocusPainted(false);
ashiquzzaman33
  • 5,781
  • 5
  • 31
  • 42
  • Thank you, but this does not work, all it does is remove the button layout, but its background still remains visible, please note that i do not want to hide the button, i want to see it but not with that ugly rectangle behind it – Francesco Rizzi Sep 19 '15 at 14:15
  • 1
    (1+) @FrancescoRizzi, Start by just using the setOpaque(false). This will get rid of the background color outside the border of the button. You can try adding in the other methods one at a time if you still have a problem (although I didn't need them). Otherwise, post a proper [SSCCE](http://sscce.org/) every time you post a question so we don't have to guess what code you are using or what LAF you are using. – camickr Sep 19 '15 at 14:30
  • 1
    Solved, it was just a problem with the panel containing the button, still thanks :) – Francesco Rizzi Sep 19 '15 at 15:44
0

you can use the following code to remove border:

yourbutton.setBorderPainted(false);
Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Batman
  • 480
  • 2
  • 8
  • Unfortunately this does not work :( all it does is remove the button layout, but its background still remains visible, please note that i do not want to hide the button, i want to see it but not with that ugly rectangle behind it – Francesco Rizzi Sep 19 '15 at 14:17