如何在javafx中单击工作日时在DatePicker中触发事件
是否可以在javafx DatePicker中每次单击周数和/或工作日时触发事件 我的意思是,我可以将actionListener设置为datepicker,当用户在某一天单击时,它将被触发。但那不是我想要的。我需要知道用户何时单击工作日本身的名称,或周数本身如何在javafx中单击工作日时在DatePicker中触发事件,javafx,datepicker,Javafx,Datepicker,是否可以在javafx DatePicker中每次单击周数和/或工作日时触发事件 我的意思是,我可以将actionListener设置为datepicker,当用户在某一天单击时,它将被触发。但那不是我想要的。我需要知道用户何时单击工作日本身的名称,或周数本身 有可能吗?提前谢谢 这会让你走上正确的方向。本演示如何将鼠标单击的事件处理程序添加到星期几节点。它还显示了如何计算其他节点的CSS 键码: 完整代码: 输出: 我知道如何获得一周中的某一天或一周的数字,但这不是我要找的。我需要知道用户何时
有可能吗?提前谢谢 这会让你走上正确的方向。本演示如何将鼠标单击的
事件处理程序添加到星期几
节点。它还显示了如何计算其他节点的CSS
键码:
完整代码:
输出:
我知道如何获得一周中的某一天或一周的数字,但这不是我要找的。我需要知道用户何时按了一周中的某一天或某周的号码,并知道他单击了其中的哪一天。这没有意义。您可以通过datePicker.getValue()
轻松确定LocalDate
按下了什么。该信息在发布的输出中。您可以清楚地看到,用户按了一周中的一天->星期四,并且用户按了一周中的一天,即第12周?我不是说在某一特定的日子单击。我想知道用户何时单击工作日本身的名称。我想知道用户何时按下星期一或星期二或第32周的数字32。请在您的问题中更好地解释。我更新了我的答案。
for (Node node : popupContent.lookupAll(".day-name-cell")) {
DateCell tempDateCell = (DateCell) node;
tempDateCell.setOnMouseClicked((event) -> {
System.out.println("You clicked: " + tempDateCell.getText());
});
}
import com.sun.javafx.scene.control.skin.DatePickerSkin;
import java.time.LocalDate;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class JavaFXApplication147 extends Application
{
@Override
public void start(Stage primaryStage)
{
DatePicker datePicker = new DatePicker(LocalDate.now());
DatePickerSkin datePickerSkin = new DatePickerSkin(datePicker);
Node popupContent = datePickerSkin.getPopupContent();
//To see day of the week nodes
for (Node node : popupContent.lookupAll(".day-name-cell")) {
node.setOnMouseClicked((event) -> {
DateCell dateCell = (DateCell) node;
System.out.println("You clicked: " + dateCell.getText());
});
}
//To see all nodes. Used to find out how to look up certain nodes
System.out.println("\nAll nodes:");
for (Node node : popupContent.lookupAll("*")) {
System.out.println("\t" + node);
}
StackPane root = new StackPane(popupContent);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
All nodes:
DatePickerContent@58c2582f[styleClass=date-picker-popup]
BorderPane@9a2c4e3[styleClass=month-year-pane]
HBox@6237f3e7[styleClass=spinner]
Button@5468474f[styleClass=button left-button]''
Label@4a04f04f[styleClass=label spinner-label]'March'
Button@68b04c02[styleClass=button right-button]''
HBox@6e61c6ba[styleClass=spinner]
Button@d7d5b3e[styleClass=button left-button]''
Label@508829bd[styleClass=label spinner-label]'2018'
Button@3837351b[styleClass=button right-button]''
Grid hgap=-1.0, vgap=-1.0, alignment=TOP_LEFT
DateCell@6a1b4345[styleClass=cell date-cell day-name-cell]'Sun'
DateCell@76997e3d[styleClass=cell date-cell day-name-cell]'Mon'
DateCell@c263fb4[styleClass=cell date-cell day-name-cell]'Tue'
DateCell@29bdab5e[styleClass=cell date-cell day-name-cell]'Wed'
DateCell@190cd447[styleClass=cell date-cell day-name-cell]'Thu'
DateCell@245929cd[styleClass=cell date-cell day-name-cell]'Fri'
DateCell@193f696d[styleClass=cell date-cell day-name-cell]'Sat'
DateCell@5d9cc64f[styleClass=cell date-cell day-cell previous-month]'25'
DateCell@224d9f57[styleClass=cell date-cell day-cell previous-month]'26'
DateCell@4fb7dd92[styleClass=cell date-cell day-cell previous-month]'27'
DateCell@2da1a108[styleClass=cell date-cell day-cell previous-month]'28'
DateCell@1634b44d[styleClass=cell date-cell day-cell]'1'
DateCell@584d26fb[styleClass=cell date-cell day-cell]'2'
DateCell@29e72b2d[styleClass=cell date-cell day-cell]'3'
DateCell@96e66f8[styleClass=cell date-cell day-cell]'4'
DateCell@3a4b2d44[styleClass=cell date-cell day-cell]'5'
DateCell@b80be08[styleClass=cell date-cell day-cell]'6'
DateCell@1b2e4216[styleClass=cell date-cell day-cell]'7'
DateCell@610dbe2d[styleClass=cell date-cell day-cell]'8'
DateCell@2cf9e45[styleClass=cell date-cell day-cell]'9'
DateCell@cb100ea[styleClass=cell date-cell day-cell]'10'
DateCell@65e6dd98[styleClass=cell date-cell day-cell]'11'
DateCell@6916ebdf[styleClass=cell date-cell day-cell]'12'
DateCell@17d57d0e[styleClass=cell date-cell day-cell]'13'
DateCell@1367994e[styleClass=cell date-cell day-cell]'14'
DateCell@40be8ca7[styleClass=cell date-cell day-cell]'15'
DateCell@1ea8cf7c[styleClass=cell date-cell day-cell]'16'
DateCell@2229ecaa[styleClass=cell date-cell day-cell]'17'
DateCell@dabac48[styleClass=cell date-cell day-cell]'18'
DateCell@3944c2ee[styleClass=cell date-cell day-cell]'19'
DateCell@614f3995[styleClass=cell date-cell day-cell]'20'
DateCell@c6ed5aa[styleClass=cell date-cell day-cell]'21'
DateCell@5cf7e183[styleClass=cell date-cell day-cell]'22'
DateCell@43bb1b41[styleClass=cell date-cell day-cell]'23'
DateCell@5ba01132[styleClass=cell date-cell day-cell]'24'
DateCell@21995c69[styleClass=cell date-cell day-cell]'25'
DateCell@42014a20[styleClass=cell date-cell day-cell]'26'
DateCell@597b2032[styleClass=cell date-cell day-cell]'27'
DateCell@20993ae[styleClass=cell date-cell day-cell today selected]'28'
DateCell@6918ed92[styleClass=cell date-cell day-cell]'29'
DateCell@2180eadb[styleClass=cell date-cell day-cell]'30'
DateCell@21fa2469[styleClass=cell date-cell day-cell]'31'
DateCell@6fa0571b[styleClass=cell date-cell day-cell next-month]'1'
DateCell@41fa4300[styleClass=cell date-cell day-cell next-month]'2'
DateCell@670abfd6[styleClass=cell date-cell day-cell next-month]'3'
DateCell@17231632[styleClass=cell date-cell day-cell next-month]'4'
DateCell@7ad68342[styleClass=cell date-cell day-cell next-month]'5'
DateCell@69273d5b[styleClass=cell date-cell day-cell next-month]'6'
DateCell@5b61dba6[styleClass=cell date-cell day-cell next-month]'7'