Skip to content
J.Zimmermann edited this page Jul 29, 2015 · 3 revisions

Sample Usage:

public class Simple extends Application {

	@Override
	public void start(Stage stage) {
		stage.setTitle("FX Keyboard (" + System.getProperty("javafx.runtime.version") + ")");
		stage.setResizable(true);

		VBox pane = new VBox(20);

		pane.getChildren().add(new Label("Text"));
		TextField tf0 = new TextField();
		tf0.setPromptText("text");
		pane.getChildren().add(tf0);

		pane.getChildren().add(new Label("Numeric"));
		TextField tf1 = new TextField();
		tf1.setPromptText("0-9");
		// Currently, the vkType property supports the following values:
		// numeric, url, email, and text
		tf1.getProperties().put("vkType", "numeric");
		pane.getChildren().add(tf1);

		Scene scene = new Scene(pane, 600, 800);

		stage.setOnCloseRequest(e -> System.exit(0));
		stage.setScene(scene);

		KeyBoardPopup popup = KeyBoardPopupBuilder.create().initLocale(Locale.GERMAN).layer(DefaultLayer.NUMBLOCK).addIRobot(new FXRobotHandler()).build();
		// open keyboard on text components
		popup.addFocusListener(scene);
		// open keyboard on double clicked text components
		popup.addDoubleClickEventFilter(stage);
		stage.show();

	}

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

}
public class JavaFXKeyboardTest extends Application {

	private static KeyBoardPopup popup;

	@Override
	public void start(Stage stage) throws Exception {
		stage.setTitle("FX Keyboard (" + System.getProperty("javafx.runtime.version") + ")");

		// load fxml resource
		Parent root = FXMLLoader.load(getClass().getResource("TestArea.fxml"));
		Scene scene = new Scene(root);

		popup = KeyBoardPopupBuilder.create()
				// initial keyboard scale
				.initScale(0.9)
				// path to your customized keyboard layouts
				.layerPath(Paths.get("numblock"))
				// choose your prefered startup locale
				.initLocale(Locale.ENGLISH)
				// choose swing or javafx keyboard controller
				.addIRobot(new FXRobotHandler())
				// customized css style
				.style(getClass().getResource("blue.css").toExternalForm())
				.build();

		popup.getKeyBoard().setOnKeyboardCloseButton(e -> popup.setVisible(false));
		popup.addDoubleClickEventFilter(stage);
		popup.addFocusListener(scene);
		
		popup.setAutoFix(true);

		stage.setScene(scene);
		popup.show(stage);
		stage.show();

	}

	public static void openKeyboard(){
		popup.setVisible(true);
	}
	
	public static void closeKeyboard(){
		popup.setVisible(false);
	}
	
	public static void main(String[] args) {
		launch(args);
	}

}
Clone this wiki locally