Java 如何使用上面的标签创建新的文本字段
我开始用Java做一个项目。Java 如何使用上面的标签创建新的文本字段,java,javafx,Java,Javafx,我开始用Java做一个项目。 我希望在JavaFX中创建一个类似于TextField的控件,但在左上角有一个标签。 此外,textfield包含SimpleBoleAnProperty,用于指示用户是否键入了基于正则表达式的有效字符串 我试图扩展Textfield并添加一个标签作为他的子项,但标签是在Textfield中创建的 这是CustomTF的代码 package OrderPackage; import javafx.animation.KeyFrame; import javafx.
我希望在JavaFX中创建一个类似于TextField的控件,但在左上角有一个标签。
此外,textfield包含SimpleBoleAnProperty,用于指示用户是否键入了基于正则表达式的有效字符串 我试图扩展Textfield并添加一个标签作为他的子项,但标签是在Textfield中创建的 这是CustomTF的代码
package OrderPackage;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.geometry.NodeOrientation;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.util.Duration;
public class CustomTF extends ValidationTextField {
private Label desc = new Label();
private Timeline animation = new Timeline();
public CustomTF() {
this("");
}
public CustomTF(String promptText) {
// this.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
this.setPromptText(promptText);
desc.setOpacity(0);
desc.textProperty().bind(this.promptTextProperty());
this.focusedProperty().addListener((obs, old, news) -> {
if (news) {
animation.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0), new KeyValue(desc.opacityProperty(), 0)),
new KeyFrame(Duration.millis(200), new KeyValue(desc.opacityProperty(), 1)),
new KeyFrame(Duration.millis(0), new KeyValue(desc.layoutYProperty(), this.getLayoutY())),
new KeyFrame(Duration.millis(200), new KeyValue(desc.layoutYProperty(), this.getLayoutY() - 25)));
}
else {
animation.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0), new KeyValue(desc.opacityProperty(), 1)),
new KeyFrame(Duration.millis(200), new KeyValue(desc.opacityProperty(), 0)),
new KeyFrame(Duration.millis(0), new KeyValue(desc.layoutYProperty(), this.getLayoutY() - 25)),
new KeyFrame(Duration.millis(250), new KeyValue(desc.layoutYProperty(), this.getLayoutY())));
}
animation.play();
animation.getKeyFrames().clear();
});
this.getChildren().addAll(desc);
}
public Label getLabelPromptText() {
return desc;
}
}
下面是ValidationTextField的代码
package OrderPackage;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.control.TextField;
public class ValidationTextField extends TextField{
private SimpleBooleanProperty validationProperty = new SimpleBooleanProperty(false);
private Validation validationRule;
public ValidationTextField() {
this(Validation.ANY);
}
public ValidationTextField(Validation validationRule) {
super();
this.validationRule = validationRule;
}
public void setValidationRule(Validation validationRule) {
this.validationRule = validationRule;
}
public boolean validate() {
return this.getText().trim().matches(validationRule.getValidation());
}
public SimpleBooleanProperty validationProperty() {
return validationProperty;
}
public String getValidation() {
return validationRule.getValidation();
}
}
这个问题太宽泛了:你需要的是一个定制的皮肤。。和/或搜索支持验证(及其可视化)的第三方控件,然后使用这些控件或了解实现所需功能的选项。使新节点扩展
VBox
。添加标签
和文本字段
。这个问题太宽泛了:你需要的是定制皮肤。。和/或搜索支持验证(及其可视化)的第三方控件,然后使用这些控件或了解实现所需功能的选项。使新节点扩展VBox
。添加标签
和文本字段
。