简体   繁体   中英

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?

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.

in your label/button you can use the textOverrun property to turn off ellipsis.

textOverrun.set(OverrunStyle.CLIP);

this is probably a bit late for you, so i am putting it here for lone wanderers digging up this question.

It puts ... because there's no room for the text. You can use bigger buttons or a smaller font but if you really want the dots gone use button.setEllipsisString(""); , but then you just get truncated text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM