当前位置: 首页>>代码示例>>Java>>正文


Java DatePicker类代码示例

本文整理汇总了Java中javafx.scene.control.DatePicker的典型用法代码示例。如果您正苦于以下问题:Java DatePicker类的具体用法?Java DatePicker怎么用?Java DatePicker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DatePicker类属于javafx.scene.control包,在下文中一共展示了DatePicker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectDate

import javafx.scene.control.DatePicker; //导入依赖的package包/类
@Test public void selectDate() {
    DatePicker datePickerNode = (DatePicker) getPrimaryStage().getScene().getRoot().lookup(".date-picker");
    IJavaFXElement datePicker = datePickers.get(0);
    Platform.runLater(() -> {
        datePicker.marathon_select(dateString);
    });
    List<Object> dates = new ArrayList<>();
    Platform.runLater(() -> {
        LocalDate value = datePickerNode.getValue();
        dates.add(datePickerNode.getConverter().toString(value));
    });
    new Wait("Waiting for date to be set.") {
        @Override public boolean until() {
            return dates.size() > 0;
        }
    };
    AssertJUnit.assertEquals(dateString, dates.get(0));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JavaFXDatePickerElementTest.java

示例2: selectEdiotrDate

import javafx.scene.control.DatePicker; //导入依赖的package包/类
@Test public void selectEdiotrDate() {
    Set<Node> datePickerNodes = getPrimaryStage().getScene().getRoot().lookupAll(".date-picker");
    List<Node> pickers = new ArrayList<>(datePickerNodes);
    DatePicker datePickerNode = (DatePicker) pickers.get(1);
    IJavaFXElement datePicker = datePickers.get(1);
    Platform.runLater(() -> {
        datePicker.marathon_select(dateString);
    });
    List<Object> dates = new ArrayList<>();
    Platform.runLater(() -> {
        LocalDate value = datePickerNode.getValue();
        dates.add(datePickerNode.getConverter().toString(value));
    });
    new Wait("Waiting for date to be set.") {
        @Override public boolean until() {
            return dates.size() > 0;
        }
    };
    AssertJUnit.assertEquals(dateString, dates.get(0));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:21,代码来源:JavaFXDatePickerElementTest.java

示例3: DatePickerSample

import javafx.scene.control.DatePicker; //导入依赖的package包/类
public DatePickerSample() {
    HBox hBox = new HBox();
    hBox.setSpacing(15);

    DatePicker uneditableDatePicker = new DatePicker();
    uneditableDatePicker.setEditable(false);

    DatePicker editablDatePicker = new DatePicker();
    editablDatePicker.setPromptText("Edit or Pick...");
    hBox.getChildren().addAll(uneditableDatePicker, editablDatePicker);
    getChildren().add(hBox);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:DatePickerSample.java

示例4: getText

import javafx.scene.control.DatePicker; //导入依赖的package包/类
@Test public void getText() {
    DatePicker datePicker = (DatePicker) getPrimaryStage().getScene().getRoot().lookup(".date-picker");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    RFXDatePicker rfxDatePicker = new RFXDatePicker(datePicker, null, null, lr);
    Platform.runLater(() -> {
        datePicker.setValue(LocalDate.now());
        text.add(rfxDatePicker._getText());
    });
    new Wait("Waiting for date picker text.") {
        @Override public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals(datePicker.getConverter().toString(LocalDate.now()), text.get(0));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:RFXDatePickerTest.java

示例5: pickEditorDate

import javafx.scene.control.DatePicker; //导入依赖的package包/类
@Test public void pickEditorDate() {
    Set<Node> datePickerNodes = getPrimaryStage().getScene().getRoot().lookupAll(".date-picker");
    List<Node> pickers = new ArrayList<>(datePickerNodes);
    DatePicker datePicker = (DatePicker) pickers.get(1);
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        RFXDatePicker rfxDatePicker = new RFXDatePicker(datePicker, null, null, lr);
        datePicker.getEditor().setText("8/8/2016");
        rfxDatePicker.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("8/8/2016", recording.getParameters()[0]);

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:RFXDatePickerTest.java

示例6: setDateFormat

import javafx.scene.control.DatePicker; //导入依赖的package包/类
/**
 * Sets a custom date format on a {@link DatePicker}. The format must be compliant with the java.time specifications.
 * @param datePicker The DatePicker object
 * @param format The date format
 */
public static void setDateFormat(DatePicker datePicker, final String format) {
	datePicker.setConverter(new StringConverter<LocalDate>() {
		DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
		
		@Override
		public String toString(LocalDate date) {
			return date != null ? df.format(date) : "";
		}

		@Override
		public LocalDate fromString(String string) {
			return (string != null && !string.isEmpty()) ? LocalDate.parse(string, df) : null;
		}
		
	});
	
}
 
开发者ID:vibridi,项目名称:fxutils,代码行数:23,代码来源:FXInput.java

示例7: createDatePicker

import javafx.scene.control.DatePicker; //导入依赖的package包/类
private void createDatePicker() {
    datePicker = new DatePicker(getDate());
    FXInput.setDateFormat(datePicker, datePattern);
   // datePicker.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    datePicker.setOnKeyReleased(keyEvent -> {
    	if(keyEvent.getCode() == KeyCode.ENTER) {
    		commitEdit(datePicker.getValue().format(dateFormatter)); // TODO check for empty/null values
    	} else if(keyEvent.getCode() == KeyCode.ESCAPE) {
    		cancelEdit();
    	}
    });
    
    datePicker.focusedProperty().addListener((obsValue, oldValue, newValue) -> {
    	if(oldValue == true && newValue == false)
    		commitEdit(datePicker.getValue().format(dateFormatter));
    });
}
 
开发者ID:vibridi,项目名称:fxutils,代码行数:18,代码来源:DatePickerTableCell.java

示例8: initTimelineViewToolBar

import javafx.scene.control.DatePicker; //导入依赖的package包/类
private void initTimelineViewToolBar() {
	timelineViewToolBar.setPrefHeight(TOOLBAR_HEIGHT);
	
	dpStart = new DatePicker(timelineView.getTimelineStart());
	FXInput.setDateFormat(dpStart, TASK_DATE_FORMAT);
	dpStart.setOnAction(event -> {
		timelineView.resetStart(dpStart.getValue());
	});
	
	dpEnd = new DatePicker(timelineView.getTimelineEnd());
	FXInput.setDateFormat(dpEnd, TASK_DATE_FORMAT);
	dpEnd.setOnAction(event -> {
		timelineView.resetEnd(dpEnd.getValue());
	});
	
	timelineViewToolBar.getItems().addAll(new Label("From: "), dpStart, new Label("To: "), dpEnd);
}
 
开发者ID:vibridi,项目名称:qgu,代码行数:18,代码来源:GanttChart.java

示例9: initializeDatePickers

import javafx.scene.control.DatePicker; //导入依赖的package包/类
/**
 * Ensures that the date pickers only allow selection of dates within the valid booking date
 * range, as defined in the specifications document.
 *
 * Chief among these rules is that bookings may not be placed more than one year in advance.
 */
private void initializeDatePickers() {
    Callback<DatePicker, DateCell> dayCellFactory =
        (final DatePicker datePicker) -> new DateCell() {
            @Override
            public void updateItem(LocalDate item, boolean empty) {
                super.updateItem(item, empty);

                if(item.isAfter(LocalDate.now().plusYears(1))) {
                    setDisable(true);
                }
                if(item.isBefore(ChronoLocalDate.from(LocalDate.now()))) {
                    setDisable(true);
                }
            }
        };
    // Disable selecting invalid check-in/check-out dates
    checkInDatePicker.setDayCellFactory(dayCellFactory);
    checkOutDatePicker.setDayCellFactory(dayCellFactory);
}
 
开发者ID:maillouxc,项目名称:git-rekt,代码行数:26,代码来源:BrowseRoomsScreenController.java

示例10: setRanges

import javafx.scene.control.DatePicker; //导入依赖的package包/类
public void setRanges(LocalDateTime startDate, LocalDateTime endDate){
    logger.debug("Setting allowed dates from {} to {}", startDate, endDate);
    final Callback<DatePicker, DateCell> dayCellFactory =
            new Callback<DatePicker, DateCell>() {
                @Override
                public DateCell call(final DatePicker datePicker) {
                    return new DateCell() {
                        @Override
                        public void updateItem(LocalDate item, boolean empty) {
                            super.updateItem(item, empty);
                            if (item.isBefore(startDate.toLocalDate()) || item.isAfter(endDate.toLocalDate())) {
                                setDisable(true);
                                setStyle("-fx-background-color: #ffc0cb;");
                            }
                        }
                    };
                }
            };
    setDayCellFactory(dayCellFactory);
}
 
开发者ID:travelimg,项目名称:travelimg,代码行数:21,代码来源:FlickrDatePicker.java

示例11: createDatePicker

import javafx.scene.control.DatePicker; //导入依赖的package包/类
private void createDatePicker() {
    datePicker = new DatePicker(getItem());
    datePicker.converterProperty().bind(converterProperty());

    datePicker.setOnAction(event -> {
        commitEdit(datePicker.getValue());
        event.consume();
    });

    datePicker.setOnKeyReleased(t -> {
        if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
            t.consume();
        }
    });
}
 
开发者ID:edvin,项目名称:tornadofx-controls,代码行数:17,代码来源:DatePickerTableCell.java

示例12: promptTextProperty

import javafx.scene.control.DatePicker; //导入依赖的package包/类
/**
 * Check bindings of the 'prompt text' property
 */
@Test(timeout = 10000)
public void promptTextProperty() {
    rememberInitialState();
    assertTrue("[Propmpt text is empty by default]", new GetAction<Boolean>() {
        @Override public void run(Object... parameters) throws Exception {
            setResult(new DatePicker().promptTextProperty().getValue().isEmpty());
        }
    }.dispatch(testedControl.getEnvironment()).booleanValue());

    final String TESTED_TEXT = "MM_dd_YY";
    final String DEFAULT_TEXT = "default";

    for(SettingType settingType : SettingType.values()) {
        System.out.format("Testing binding:%s\n", settingType.toString());

        setPropertyByTextField(settingType, Properties.prompttext, TESTED_TEXT);
        checkTextFieldText(Properties.prompttext, TESTED_TEXT);

        switchOffBinding(settingType, Properties.prompttext);
        setPropertyByTextField(SettingType.SETTER, Properties.prompttext, DEFAULT_TEXT);
    }
    checkFinalState();
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:27,代码来源:DatePickerTest.java

示例13: start

import javafx.scene.control.DatePicker; //导入依赖的package包/类
@Override
public void start(Stage primaryStage)
{
	FXMonthView monthView = new FXMonthView();
	
	DatePicker datePicker = new DatePicker();
	datePicker.valueProperty().bindBidirectional(monthView.selectedDateProperty());
	
	FXFormPane controls = new FXFormPane();
	controls.addChild(datePicker);
	
	BorderPane root = new BorderPane();
	root.setBottom(controls);
	root.setCenter(monthView);
	BorderPane.setAlignment(root.getCenter(), Pos.CENTER);
	BorderPane.setMargin(monthView, new Insets(10, 10, 10, 10));
	
	primaryStage.setScene(new Scene(root));
	primaryStage.setTitle("JavaFX FXMonthView Test");
	primaryStage.show();
}
 
开发者ID:ivartanian,项目名称:JVx.javafx,代码行数:22,代码来源:FXMonthViewTestMain.java

示例14: handleClearButton

import javafx.scene.control.DatePicker; //导入依赖的package包/类
/**
 * Clears all data on-screen in text fields,
 * text-area's, and date-picker's.
 *
 * @param event The action event.
 */
@FXML
public void handleClearButton(final ActionEvent event) {
    Object[] o = userDataGroup.getChildren().toArray();
    for (int i = 0; i < o.length; i++) {
        if (o[i] instanceof TextField) {
            ((TextField) o[i]).clear();
        } else if (o[i] instanceof TextArea) {
            ((TextArea) o[i]).clear();
        } else if (o[i] instanceof DatePicker) {
            ((DatePicker) o[i]).setValue(null);
        }
    }
    selectAParkDropDownMenu.setValue(null);
    enterYear.setValue(null);
    enterMonth.setValue(null);
    resetValidation();
}
 
开发者ID:MoneyBeets,项目名称:Narvaro,代码行数:24,代码来源:Controller.java

示例15: UpdateDatePicker

import javafx.scene.control.DatePicker; //导入依赖的package包/类
private void UpdateDatePicker(){
	Callback<DatePicker, DateCell> dayCellFactory = dp -> new DateCell()
       {
           @Override
           public void updateItem(LocalDate item, boolean empty)
           {
               super.updateItem(item, empty);

               if(item.isBefore(Instant.ofEpochMilli(repoBeginDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDate()) 
               		|| item.isAfter(Instant.ofEpochMilli(repoEndDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDate()))
               {
                   setStyle("-fx-background-color: #ffc0cb;");
                   setDisable(true);

                   /* When Hijri Dates are shown, setDisable() doesn't work. Here is a workaround */
                 //  addEventFilter(MouseEvent.MOUSE_CLICKED, e -> e.consume());
               }
               
    
           }
       };

       beginDate.setDayCellFactory(dayCellFactory);
       endDate.setDayCellFactory(dayCellFactory);
}
 
开发者ID:gems-uff,项目名称:dominoes,代码行数:26,代码来源:ProjectInfoPane.java


注:本文中的javafx.scene.control.DatePicker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。