1

I have created a JavaFX button and would like to make it display the complete text. I am not able to find a workaround for this. I know we can achieve multi line text display.But then if the word comprises of more than a certain number of letters, the button doesn't let the whole word fit in and displays ellipsis instead.

Below is how my button looks. As you can see there's so much space around the button text, yet it doesn't display the whole word.

enter image description here

----EDIT 1 : START----

This question was marked as duplicate by referring to this question : How to prevent text from turning to ellipsis on small buttons in JavaFX?

However, this is not what I am looking for. I think I did a good job at explaining my scenarion in my OP. But I will try again to elaborate on it.

1). First of all, my button is not a small button as the referred post's title reads.

2). Secondly, my intention is not to alter the size of button. I want the button to remain as it is.

3). Thirdly, my issue is not with ellipsis. I know how to get rid of the ellipsis.

4). Finally, MY real issue : How to alter the button, so that it doesnot leave so much of space around its text. I had already provided the image of my button. I would like to make use of the button region that I marked with red arrow. As you can see, there is so much space left, but still the whole word does not show and has ellipsis.

SOLUTION : START

In the meantime I came across a very helpful link : Confgure margin for individual element via java fx css

This is what solves my issue and not the original post that was referred to.

I added -fx-padding: 1px; css property for my buttons and everything works liek a charm now.

Below is how my buttons look right now :

enter image description here

SOLUTION :END

----EDIT 1 : END----

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • This is not duplicate. Will youo please remove the duplicate tag. I have already tried the suggestions. Don't know what else I need to add in order to get the duplicate tag removed. Still i'll try to add some details to my original question. – Asif Kamran Malick Jun 01 '19 at 11:44
  • Won't this be a problem if my font has larger metrics? Would a tooltip be helpful here? – trashgod Jun 01 '19 at 12:41
  • @trashgod I am just a beginner in JavaFX world. Sorry, but I'm not sure of the side-effects. If you could explain the side-effects(if any) a bit may be in the form of an answer,so that I can mark it as accepted. – Asif Kamran Malick Jun 01 '19 at 14:16
  • Having seen this [pitfall](https://stackoverflow.com/a/12532237/230513) in Swing, I try to avoid interfering with the JavaFX preferred size calculation. – trashgod Jun 01 '19 at 16:31

0 Answers0