This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JButton with no Border Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton with no Border" Watch "JButton with no Border" New topic

JButton with no Border

Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
I want to add a JButton with no border, so that if I set the button to be disabled the button should not be visible.
Thank you
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Well, losing the Border of a JButton does not make it invisible. It only removes the border. To do this you simply use the setBorderPainted(boolean) method of JButton.
If you want the button to disappear if it is disabled, you will have to remove it from whatever container you have it on. container.remove(button). And don't foget to call repaint and/or revalidate so that the changes take affect.

GenRocket - Experts at Building Test Data
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
to make the button invisible, you can call

to make it visible, use visible(true).
this works most nicely!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JButton with no Border
It's not a secret anymore!