Orange Peel
Orange Peel

Reputation: 484

Detect text overflow in JButton

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?

Upvotes: 3

Views: 143

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172488

You can try to check it like this:

if (myBtn.getPreferredSize().width > myBtn.getSize().width)

Upvotes: 1

Related Questions