/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ package csstests; import com.sun.javafx.runtime.VersionInfo; import java.util.Timer; import java.util.TimerTask; import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Control; import javafx.scene.control.DatePicker; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; /** * * @author sergey.lugovoy@oracle.com */ public class DatePickerTest extends Application { BorderPane root = new BorderPane(); DatePicker btn; @Override public void start(Stage stage) throws Exception { root.setTop(new Button("Button")); Scene scene = new Scene(root, 300, 300); stage.setScene(scene); stage.setTitle(VersionInfo.getRuntimeVersion()); stage.show(); new Thread(new Runnable() { @Override public void run() { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Platform.runLater(new Runnable() { @Override public void run() { root.setCenter(getDatePicker()); System.out.println("add date picker"); } }); } }, 1000); } }).start(); } private Control getDatePicker() { if (btn == null) { btn = new DatePicker(); } return btn; } /** * The main() method is ignored in correctly deployed JavaFX application. * main() serves only as fallback in case the application can not be * launched through deployment artifacts, e.g., in IDEs with limited FX * support. NetBeans ignores main(). * * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }