3

I am trying to detect whether the text of a JButton fits within the current width, and doesn't overflow like this:

Like this

Is this possible, if so how?

2
  • might this help? Commented Oct 23, 2015 at 8:02
  • 2
    How about: if(getPrefferredSize().width > getSize().width)? Commented Oct 23, 2015 at 8:06

1 Answer 1

1

You can try to check it like this:

if (myBtn.getPreferredSize().width > myBtn.getSize().width) 
Sign up to request clarification or add additional context in comments.

2 Comments

Should be getPreferredSize()
@OrangePeel:- Indeed, a typo. Fixed that!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.