Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

java - How to prevent text from turning to ellipsis on small buttons in JavaFX?

If I make button relatively small, it's caption turns to ellipsis.

How to turn off this feature?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Don't let the button go below it's preferred size, then it will never need to elide the text of the button label:

button.setMinSize(Button.USE_PREF_SIZE, Button.USE_PREF_SIZE);

I want to make very small button

You can use any of the below either separately or in combination:

  1. Apply CSS to use a very small font in the button.
  2. Make the label text for the button very short.
  3. Use brian's answer which proposes explicitly setting the ellipse string to empty.
  4. Use a small graphic icon instead of text.

You can use setMinSize as documented above in all cases (if you wish the button not to go below a preferred size truncating or eliding content).

In all cases, if you wish, you can also apply CSS to minimize the padding between the label and button the border.

From your previous comment (I want to use simple captions like "<" and ">"), I think option 2 (Make the label text for the button very short) is what you want.

You may also be interested in Joel's Designing for People Who Have Better Things To Do With Their Lives which would indicate, usability-wise that very small buttons are usually a pretty bad idea.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...