gpt4 book ai didi

java - 如何从日期选择器中获取字符串形式的值,即使它不是日期格式(JavaFX)?

转载 作者:行者123 更新时间:2023-12-01 10:11:38 27 4
gpt4 key购买 nike

如何以纯字符串形式检索,无论他们输入什么,即使它只是随机字母?谢谢。

最佳答案

解决方案

您可以监听DatePicker编辑器的textProperty(或绑定(bind)到它)。这是使用监听器的示例,日期选择器编辑器中的任何文本也会在其上方的标签中转发。

Label typedData = new Label();
picker.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
typedData.setText(newValue);
});

示例应用

xyzzy

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class PickingDates extends Application {
@Override
public void start(final Stage stage) throws Exception {
DatePicker picker = new DatePicker();
Label typedData = new Label();
picker.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
typedData.setText(newValue);
});
Button button = new Button("Button");

final VBox layout = new VBox(10, typedData, picker, button);
layout.setPadding(new Insets(10));
Scene scene = new Scene(layout);
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch(args);
}
}

关于java - 如何从日期选择器中获取字符串形式的值,即使它不是日期格式(JavaFX)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36091951/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com