Java Code Examples for javafx.scene.control.TextField#setMaxHeight()

The following examples show how to use javafx.scene.control.TextField#setMaxHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringBindingSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public StringBindingSample() {
    final SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy");
    final TextField dateField = new TextField();
    dateField.setPromptText("Enter a birth date");
    dateField.setMaxHeight(TextField.USE_PREF_SIZE);
    dateField.setMaxWidth(TextField.USE_PREF_SIZE);

    Label label = new Label();
    label.textProperty().bind(new StringBinding() {
        {
            bind(dateField.textProperty());
        }            
        @Override protected String computeValue() {
            try {
                Date date = format.parse(dateField.getText());
                Calendar c = Calendar.getInstance();
                c.setTime(date);

                Date today = new Date();
                Calendar c2 = Calendar.getInstance();
                c2.setTime(today);

                if (c.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) - 1
                        && c.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
                    return "You were born yesterday";
                } else {
                    return "You were born " + format.format(date);
                }
            } catch (Exception e) {
                return "Please enter a valid birth date (mm/dd/yyyy)";
            }
        }
    });

    VBox vBox = new VBox(7);
    vBox.setPadding(new Insets(12));
    vBox.getChildren().addAll(label, dateField);
    getChildren().add(vBox);
}
 
Example 2
Source File: TextValidatorSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TextValidatorSample() {
    String validatorCss = TextValidatorSample.class.getResource("Validators.css").toExternalForm();
    
    TextField dateField = new TextField();
    dateField.setPromptText("Enter a Large Number");
    dateField.setMaxHeight(TextField.USE_PREF_SIZE);

    TextInputValidatorPane<TextField> pane = new TextInputValidatorPane<TextField>();
    pane.setContent(dateField);
    pane.setValidator(new Validator<TextField>() {
        public ValidationResult validate(TextField control) {
            try {
                String text = control.getText();
                if (text == null || text.trim().equals("")) return null;
                double d = Double.parseDouble(text);
                if (d < 1000) {
                    return new ValidationResult("Should be > 1000", ValidationResult.Type.WARNING);
                }
                return null; // succeeded
            } catch (Exception e) {
                // failed
                return new ValidationResult("Bad number", ValidationResult.Type.ERROR);
            }
        }
    });

    StackPane rootSP = new StackPane();
    rootSP.setPadding(new Insets(12));
    rootSP.getChildren().add(pane);
    pane.getStylesheets().add(validatorCss);
    getChildren().add(rootSP);
}
 
Example 3
Source File: StringBindingSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public StringBindingSample() {
    final SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy");
    final TextField dateField = new TextField();
    dateField.setPromptText("Enter a birth date");
    dateField.setMaxHeight(TextField.USE_PREF_SIZE);
    dateField.setMaxWidth(TextField.USE_PREF_SIZE);

    Label label = new Label();
    label.textProperty().bind(new StringBinding() {
        {
            bind(dateField.textProperty());
        }            
        @Override protected String computeValue() {
            try {
                Date date = format.parse(dateField.getText());
                Calendar c = Calendar.getInstance();
                c.setTime(date);

                Date today = new Date();
                Calendar c2 = Calendar.getInstance();
                c2.setTime(today);

                if (c.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) - 1
                        && c.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
                    return "You were born yesterday";
                } else {
                    return "You were born " + format.format(date);
                }
            } catch (Exception e) {
                return "Please enter a valid birth date (mm/dd/yyyy)";
            }
        }
    });

    VBox vBox = new VBox(7);
    vBox.setPadding(new Insets(12));
    vBox.getChildren().addAll(label, dateField);
    getChildren().add(vBox);
}
 
Example 4
Source File: TextValidatorSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TextValidatorSample() {
    String validatorCss = TextValidatorSample.class.getResource("Validators.css").toExternalForm();
    
    TextField dateField = new TextField();
    dateField.setPromptText("Enter a Large Number");
    dateField.setMaxHeight(TextField.USE_PREF_SIZE);

    TextInputValidatorPane<TextField> pane = new TextInputValidatorPane<TextField>();
    pane.setContent(dateField);
    pane.setValidator(new Validator<TextField>() {
        public ValidationResult validate(TextField control) {
            try {
                String text = control.getText();
                if (text == null || text.trim().equals("")) return null;
                double d = Double.parseDouble(text);
                if (d < 1000) {
                    return new ValidationResult("Should be > 1000", ValidationResult.Type.WARNING);
                }
                return null; // succeeded
            } catch (Exception e) {
                // failed
                return new ValidationResult("Bad number", ValidationResult.Type.ERROR);
            }
        }
    });

    StackPane rootSP = new StackPane();
    rootSP.setPadding(new Insets(12));
    rootSP.getChildren().add(pane);
    pane.getStylesheets().add(validatorCss);
    getChildren().add(rootSP);
}
 
Example 5
Source File: WebViewBrowser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public WebViewPane() {
    VBox.setVgrow(this, Priority.ALWAYS);
    setMaxWidth(Double.MAX_VALUE);
    setMaxHeight(Double.MAX_VALUE);

    WebView view = new WebView();
    view.setMinSize(500, 400);
    view.setPrefSize(500, 400);
    final WebEngine eng = view.getEngine();
    eng.load("http://www.oracle.com/us/index.html");
    final TextField locationField = new TextField("http://www.oracle.com/us/index.html");
    locationField.setMaxHeight(Double.MAX_VALUE);
    Button goButton = new Button("Go");
    goButton.setDefaultButton(true);
    EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent event) {
            eng.load(locationField.getText().startsWith("http://") ? locationField.getText() :
                    "http://" + locationField.getText());
        }
    };
    goButton.setOnAction(goAction);
    locationField.setOnAction(goAction);
    eng.locationProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            locationField.setText(newValue);
        }
    });
    GridPane grid = new GridPane();
    grid.setVgap(5);
    grid.setHgap(5);
    GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
    GridPane.setConstraints(goButton,1,0);
    GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
    grid.getColumnConstraints().addAll(
            new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
            new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
    );
    grid.getChildren().addAll(locationField, goButton, view);
    getChildren().add(grid);
}
 
Example 6
Source File: WebViewEventDispatcher.java    From oim-fx with MIT License 4 votes vote down vote up
public WebViewPane() {
	VBox.setVgrow(this, Priority.ALWAYS);
	setMaxWidth(Double.MAX_VALUE);
	setMaxHeight(Double.MAX_VALUE);

	TextField locationField = new TextField("http://www.baidu.com");
	Button goButton = new Button("Go");

	WebEngine webEngine = webView.getEngine();
	page = Accessor.getPageFor(webEngine);
	page.setJavaScriptEnabled(true);

	webView.setMinSize(500, 400);
	webView.setPrefSize(500, 400);

	webEngine.load("http://www.baidu.com");

	page.setEditable(true);

	// EventDispatcher eventDispatcher=new EventDispatcher() {
	//
	// @Override
	// public Event dispatchEvent(Event event, EventDispatchChain tail)
	// {
	// //tail.dispatchEvent(event);
	// if(event.getEventType()==MouseEvent.ANY) {
	//
	// }
	// return event;
	// }
	//
	// };
	registerEventHandlers();
	

	webView.setEventDispatcher(internalEventDispatcher);
	
	System.out.println(webView.getEventDispatcher());
	// webView.addEventHandler(eventType, eventHandler);
	// webView.buildEventDispatchChain(tail)

	EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			webEngine.load(locationField.getText().startsWith("http://") ? locationField.getText() : "http://" + locationField.getText());
		}
	};

	goButton.setDefaultButton(true);
	goButton.setOnAction(goAction);

	locationField.setMaxHeight(Double.MAX_VALUE);
	locationField.setOnAction(goAction);

	webEngine.locationProperty().addListener(new ChangeListener<String>() {
		@Override
		public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
			locationField.setText(newValue);
		}
	});

	GridPane grid = new GridPane();
	grid.setVgap(5);
	grid.setHgap(5);
	GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
	GridPane.setConstraints(goButton, 1, 0);
	GridPane.setConstraints(webView, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
	grid.getColumnConstraints().addAll(
			new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
			new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true));
	grid.getChildren().addAll(locationField, goButton, webView);
	getChildren().add(grid);
}
 
Example 7
Source File: WebViewBrowser.java    From oim-fx with MIT License 4 votes vote down vote up
public WebViewPane() {
	VBox.setVgrow(this, Priority.ALWAYS);
	setMaxWidth(Double.MAX_VALUE);
	setMaxHeight(Double.MAX_VALUE);

	WebView webView = new WebView();
	webView.setMinSize(500, 400);
	webView.setPrefSize(500, 400);
	final WebEngine webEngine = webView.getEngine();
	webEngine.load("http://www.baidu.com");

	final TextField locationField = new TextField("http://www.baidu.com");
	Button goButton = new Button("Go");

	EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			webEngine.load(locationField.getText().startsWith("http://") ? locationField.getText() : "http://" + locationField.getText());
		}
	};

	goButton.setDefaultButton(true);
	goButton.setOnAction(goAction);

	locationField.setMaxHeight(Double.MAX_VALUE);
	locationField.setOnAction(goAction);
	
	webEngine.locationProperty().addListener(e->{
		System.out.println(webEngine.getLocation());
	});
	
	webEngine.locationProperty().addListener(new ChangeListener<String>() {
		@Override
		public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
			locationField.setText(newValue);
		}
	});
	
	WebPage webPage  = Accessor.getPageFor(webEngine);
	
	webPage.setEditable(true);
	
	GridPane grid = new GridPane();
	grid.setVgap(5);
	grid.setHgap(5);
	GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
	GridPane.setConstraints(goButton, 1, 0);
	GridPane.setConstraints(webView, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
	grid.getColumnConstraints().addAll(
			new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
			new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true));
	grid.getChildren().addAll(locationField, goButton, webView);
	getChildren().add(grid);
}
 
Example 8
Source File: WebPanel.java    From Quelea with GNU General Public License v3.0 4 votes vote down vote up
private void setupNavigationBarContent() {
    back = new Button("", getButtonImageView("file:icons/arrow-back.png"));
    back.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.back();
        }
    });
    forward = new Button("", getButtonImageView("file:icons/arrow-forward.png"));
    forward.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.forward();
        }
    });
    reload = new Button("", getButtonImageView("file:icons/reload.png"));
    reload.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.reload();
        }
    });
    url = new TextField();
    url.setPrefHeight(32);
    url.setMaxHeight(32);
    url.setStyle(""
            + "-fx-font-size: 14px;"
            + "-fx-font-weight: bold;"
            + "-fx-font-family: fantasy;");
    url.setTooltip(new Tooltip("Change URL"));
    url.setOnKeyReleased(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) {
            if (wd != null) {
                wd.setUrl(url.getText());
            }
        }
    });
    go = new Button("", getButtonImageView("file:icons/send.png"));
    go.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.setUrl(url.getText());
        }
    });
    plus = new Button("", getButtonImageView("file:icons/zoom-in.png"));
    plus.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.zoom(true);
        }
    });
    minus = new Button("", getButtonImageView("file:icons/zoom-out.png"));
    minus.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.zoom(false);
        }
    });
}