如何将一次在文本字段中可见的字符数限制为小于文本字段的宽度? [英] How do I limit the number of characters visible in a text field at a time to less than the textfield's width?

查看:66
本文介绍了如何将一次在文本字段中可见的字符数限制为小于文本字段的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过遵循

我想做的是代替 TextField 移动&当我到达 TextField 的边缘时,剪掉文本,当我到达图像的左边缘时,它应该开始剪掉可见的文本.我该怎么办?

解决方案

执行此操作的最简单方法可能是在 TextField 的右侧设置填充以解决图片问题:

  -fx-padding:4px 25px 4px 7px; 

这将保留 top bottom left 的默认填充,同时更新 right 价值.这里的 25px 可能需要根据您的图像进行调整,但这是我的示例:

  textField.setStyle("-fx-background-image:url('resources/play.png');"+"-fx-background-repeat:不重复;"+"-fx-background-position:右中心;"+"-fx-padding:4px 25px 4px 7px;"); 

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;"
);

这篇关于如何将一次在文本字段中可见的字符数限制为小于文本字段的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆