• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButtons, border around text on

 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm right in saying the text on a JButton is actually a JLabel.

But can someone tell me how to remove the border from that JLabel given that it is hidden inside the Button? Do I have to subclass JButton to provide this functionality?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harold Lime wrote:I think I'm right in saying the text on a JButton is actually a JLabel.

Nope, it's not.

But can someone tell me how to remove the border from that JLabel given that it is hidden inside the Button? Do I have to subclass JButton to provide this functionality?

No need to subclass that I know of.
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But can someone tell me how to remove the border


The Border belongs to the button. The space can be adjusted as follows:

 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete stein wrote:
Harold Lime wrote:I think I'm right in saying the text on a JButton is actually a JLabel.

Nope, it's not.


I stand corrected.

I figured out how to sort it too, I can just omit the default text and then add a JLabel onto the button - easy.

Edit:

Or could do what you said while I was typing my reply...
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harold Lime wrote:I think I'm right in saying the text on a JButton is actually a JLabel.

No, as already mentioned.

But can someone tell me how to remove the border from that JLabel given that it is hidden inside the Button? Do I have to subclass JButton to provide this functionality?

Check out the setBorderPainted() and setContentAreaFilled() methods. JButton inherits them from AbstractButton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic