I have included an image in my JavaFX TextField
by following this post, but now my problem is that the text can overflow to cover up the image, like this:
What I want to do is, instead of the TextField
moving & cutting off the text when I get to the edge of the TextField
, it should start cutting off visible text when I get to the left edge of the image. How can I do this?
Probably the simplest way to do this is to set the padding on the right side of your TextField
to account for the image:
-fx-padding: 4px 25px 4px 7px;
This will keep the default padding for the top
, bottom
, and left
, while updating the right
value. The 25px
here may need to be adjusted based on your image, but here's my example:
textField.setStyle(
"-fx-background-image: url('resources/play.png');" +
"-fx-background-repeat: no-repeat;" +
"-fx-background-position: right center;" +
"-fx-padding: 4px 25px 4px 7px;"
);