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

The following examples show how to use javafx.scene.control.TextField#setMaxWidth() . 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: ColorChooser.java    From LogFX with GNU General Public License v3.0 6 votes vote down vote up
private static TextField fieldFor( Rectangle colorRectangle,
                                   String toolTipText,
                                   Consumer<? super Color> onUpdate ) {
    TextField field = new TextField( colorRectangle.getFill().toString() );
    field.setTooltip( new Tooltip( toolTipText ) );
    field.setMinWidth( 30 );
    field.setMaxWidth( 114 );
    field.textProperty().addListener( ( ignore, oldValue, newValue ) -> {
        try {
            Color colorValue = Color.valueOf( newValue );
            colorRectangle.setFill( colorValue );
            field.getStyleClass().remove( "error" );
            onUpdate.accept( colorValue );
        } catch ( IllegalArgumentException e ) {
            if ( !field.getStyleClass().contains( "error" ) ) {
                field.getStyleClass().add( "error" );
            }
            log.debug( "Invalid color entered" );
        }
    } );
    return field;
}
 
Example 2
Source File: GroupAndDatasetStructure.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public Node createNode()
{
	final TextField groupField = new TextField(group.getValue());
	groupField.setMinWidth(0);
	groupField.setMaxWidth(Double.POSITIVE_INFINITY);
	groupField.setPromptText(groupPromptText);
	groupField.textProperty().bindBidirectional(group);
	final ComboBox<String> datasetDropDown = new ComboBox<>(datasetChoices);
	datasetDropDown.setPromptText(datasetPromptText);
	datasetDropDown.setEditable(false);
	datasetDropDown.valueProperty().bindBidirectional(dataset);
	datasetDropDown.setMinWidth(groupField.getMinWidth());
	datasetDropDown.setPrefWidth(groupField.getPrefWidth());
	datasetDropDown.setMaxWidth(groupField.getMaxWidth());
	datasetDropDown.disableProperty().bind(this.isDropDownReady);
	final GridPane grid = new GridPane();
	grid.add(groupField, 0, 0);
	grid.add(datasetDropDown, 0, 1);
	GridPane.setHgrow(groupField, Priority.ALWAYS);
	GridPane.setHgrow(datasetDropDown, Priority.ALWAYS);
	final Button button = new Button("Browse");
	button.setOnAction(event -> {
		Optional.ofNullable(onBrowseClicked.apply(group.getValue(), grid.getScene())).ifPresent(group::setValue);
	});
	grid.add(button, 1, 0);

	groupField.effectProperty().bind(
			Bindings.createObjectBinding(
					() -> groupField.isFocused() ? this.textFieldNoErrorEffect : groupErrorEffect.get(),
					groupErrorEffect,
					groupField.focusedProperty()
			                            ));

	return grid;
}
 
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: 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 5
Source File: ClearingTextFieldDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start(final Stage stage)
{
    final TextField text = new ClearingTextField();
    text.setMaxWidth(Double.MAX_VALUE);
    text.setOnAction(event -> System.out.println("Text is '" + text.getText() + "'"));
    final BorderPane layout = new BorderPane(text);
    stage.setScene(new Scene(layout));
    stage.show();
}
 
Example 6
Source File: FormDemo.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
public void start(Stage stage) throws Exception {
	Customer customer = Customer.createSample(555);
	DirtyState dirtyState = new DirtyState(customer);

	Form form = new Form();
	form.setPadding(new Insets(20));

	Fieldset contactInfo = form.fieldset("Contact Information");

	TextField idInput = new TextField();
	idInput.textProperty().bindBidirectional(customer.idProperty(), new NumberStringConverter());
	contactInfo.field("Id", idInput);

	TextField usernameInput = new TextField();
	usernameInput.textProperty().bindBidirectional(customer.usernameProperty());
	contactInfo.field("Username", usernameInput);

	TextField zipInput = new TextField();
	zipInput.textProperty().bindBidirectional(customer.zipProperty());
	zipInput.setMinWidth(80);
	zipInput.setMaxWidth(80);
	TextField cityInput = new TextField();
	cityInput.textProperty().bindBidirectional(customer.cityProperty());
	contactInfo.field("Zip/City", zipInput, cityInput);

	Button saveButton = new Button("Save");
	saveButton.disableProperty().bind(dirtyState.not());
	saveButton.setOnAction(event -> dirtyState.reset());

	Button undoButton = new Button("Undo");
	undoButton.setOnAction(event -> dirtyState.undo());
	undoButton.visibleProperty().bind(dirtyState);
	contactInfo.field(saveButton, undoButton);

	stage.setScene(new Scene(form, 400,-1));

	stage.show();
}
 
Example 7
Source File: JavaFxSelectionComponentFactory.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
FileSelector(
    final ClientSetting<Path> clientSetting,
    final BiFunction<Window, /* @Nullable */ Path, /* @Nullable */ Path> chooseFile) {
  this.clientSetting = clientSetting;
  final @Nullable Path initialValue = clientSetting.getValue().orElse(null);
  final HBox wrapper = new HBox();
  textField = new TextField(SelectionComponentUiUtils.toString(clientSetting.getValue()));
  textField
      .prefColumnCountProperty()
      .bind(Bindings.add(1, Bindings.length(textField.textProperty())));
  textField.setMaxWidth(Double.MAX_VALUE);
  textField.setMinWidth(100);
  textField.setDisable(true);
  final Button chooseFileButton = new Button("...");
  selectedPath = initialValue;
  chooseFileButton.setOnAction(
      e -> {
        final @Nullable Path path =
            chooseFile.apply(chooseFileButton.getScene().getWindow(), selectedPath);
        if (path != null) {
          selectedPath = path;
          textField.setText(path.toString());
        }
      });
  wrapper.getChildren().addAll(textField, chooseFileButton);
  getChildren().add(wrapper);
}
 
Example 8
Source File: FileSystem.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public GenericBackendDialogN5 backendDialog(ExecutorService propagationExecutor) throws IOException {
	final ObjectField<String, StringProperty> containerField = ObjectField.stringField(container.get(), ObjectField.SubmitOn.ENTER_PRESSED, ObjectField.SubmitOn.ENTER_PRESSED);
	final TextField containerTextField = containerField.textField();
	containerField.valueProperty().bindBidirectional(container);
	containerTextField.setMinWidth(0);
	containerTextField.setMaxWidth(Double.POSITIVE_INFINITY);
	containerTextField.setPromptText("N5 container");

	final EventHandler<ActionEvent> onBrowseButtonClicked = event -> {

		final File initialDirectory = Optional
				.ofNullable(container.get())
				.map(File::new)
				.filter(File::exists)
				.filter(File::isDirectory)
				.orElse(new File(DEFAULT_DIRECTORY));
		updateFromDirectoryChooser(initialDirectory, containerTextField.getScene().getWindow());

	};

	final Consumer<String> processSelection = ThrowingConsumer.unchecked(selection -> {
		LOG.info("Got selection {}", selection);

		if (selection == null)
			return;

		if (isN5Container(selection)) {
			container.set(null);
			container.set(selection);
			return;
		}

		updateFromDirectoryChooser(Paths.get(selection).toFile(), containerTextField.getScene().getWindow());


	});

	final MenuButton menuButton = BrowseRecentFavorites.menuButton("_Find", Lists.reverse(PainteraCache.readLines(this.getClass(), "recent")), FAVORITES, onBrowseButtonClicked, processSelection);

	GenericBackendDialogN5 d = new GenericBackendDialogN5(containerTextField, menuButton, "N5", writerSupplier, propagationExecutor);
	final String path = container.get();
	updateWriterSupplier(path);
	return d;
}
 
Example 9
Source File: HDF5.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public GenericBackendDialogN5 backendDialog(ExecutorService propagationExecutor) {
	final ObjectField<String, StringProperty> containerField = ObjectField.stringField(container.get(), ObjectField.SubmitOn.ENTER_PRESSED, ObjectField.SubmitOn.ENTER_PRESSED);
	final TextField containerTextField = containerField.textField();
	containerField.valueProperty().bindBidirectional(container);
	containerTextField.setMinWidth(0);
	containerTextField.setMaxWidth(Double.POSITIVE_INFINITY);
	containerTextField.setPromptText("HDF5 file");

	final Consumer<Event> onClick = event -> {
		final File initialDirectory = Optional
				.ofNullable(container.get())
				.map(File::new)
				.map(f -> f.isFile() ? f.getParentFile() : f)
				.filter(File::exists)
				.orElse(new File(USER_HOME));
		updateFromFileChooser(initialDirectory, containerTextField.getScene().getWindow());
	};

	final Consumer<String> processSelection = ThrowingConsumer.unchecked(selection -> {
		LOG.info("Got selection {}", selection);
		if (selection == null)
			return;

		if (isHDF5(selection)) {
			container.set(selection);
			return;
		}
		updateFromFileChooser(new File(selection), containerTextField.getScene().getWindow());
	});

	final MenuButton menuButton = BrowseRecentFavorites.menuButton(
			"_Find",
			Lists.reverse(PainteraCache.readLines(this.getClass(), "recent")),
			FAVORITES,
			onClick::accept,
			processSelection);


	GenericBackendDialogN5 d = new GenericBackendDialogN5(containerTextField, menuButton, "N5", writerSupplier, propagationExecutor);
	final String path = container.get();
	if (path != null && new File(path).isFile())
		writerSupplier.set(ThrowingSupplier.unchecked(() -> new N5HDF5Writer(path, 64, 64, 64)));
	return d;
}
 
Example 10
Source File: SiteListStage.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
public SiteListStage (Preferences prefs, String key, int max, boolean show3270e)
{
  super (prefs);

  setTitle ("Site Manager");

  readPrefs (key, max);

  fields.add (new PreferenceField (key + " name", 150, Type.TEXT));
  fields.add (new PreferenceField ("URL", 150, Type.TEXT));
  fields.add (new PreferenceField ("Port", 50, Type.NUMBER));
  fields.add (new PreferenceField ("Ext", 50, Type.BOOLEAN));
  fields.add (new PreferenceField ("Model", 40, Type.NUMBER));
  fields.add (new PreferenceField ("Plugins", 50, Type.BOOLEAN));
  fields.add (new PreferenceField ("Save folder", 80, Type.TEXT));

  VBox vbox = getHeadings ();

  // input fields
  for (Site site : sites)
  {
    HBox hbox = new HBox ();
    hbox.setSpacing (5);
    hbox.setPadding (new Insets (0, 5, 0, 5));    // trbl

    for (int i = 0; i < fields.size (); i++)
    {
      PreferenceField field = fields.get (i);
      if (field.type == Type.TEXT || field.type == Type.NUMBER)
      {
        TextField textField = site.getTextField (i);
        textField.setMaxWidth (field.width);
        hbox.getChildren ().add (textField);
      }
      else if (field.type == Type.BOOLEAN)
      {
        HBox box = new HBox ();
        CheckBox checkBox = site.getCheckBoxField (i);
        box.setPrefWidth (field.width);
        box.setAlignment (Pos.CENTER);
        box.getChildren ().add (checkBox);
        hbox.getChildren ().add (box);
      }
    }
    vbox.getChildren ().add (hbox);
  }

  BorderPane borderPane = new BorderPane ();
  borderPane.setCenter (vbox);
  borderPane.setBottom (buttons ());

  Scene scene = new Scene (borderPane);
  setScene (scene);

  saveButton.setOnAction (e -> save (key));
  cancelButton.setOnAction (e -> this.hide ());
  editListButton.setOnAction (e -> this.show ());
}
 
Example 11
Source File: FXMLResultOutputController.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
private void showRaceReportOutputTarget(RaceOutputTarget t){
        HBox rotHBox = new HBox();
        rotHBox.setSpacing(4);
        ComboBox<ReportDestination> destinationChoiceBox = new ComboBox();
        
        //destinationChoiceBox.getItems().setAll(resultsDAO.listReportDestinations());
        
        destinationChoiceBox.setItems(resultsDAO.listReportDestinations());
        
        // ChoserBox for the OutputDestination
        destinationChoiceBox.getSelectionModel().selectedIndexProperty().addListener((ObservableValue<? extends Number> observableValue, Number number, Number number2) -> {
            if (t.getID() < 0) return; // deleted
            
            ReportDestination op = destinationChoiceBox.getItems().get((Integer) number2);
//            if(! Objects.equals(destinationChoiceBox.getSelectionModel().getSelectedItem(),op)) {
//                t.setOutputDestination(op.getID());
//                resultsDAO.saveRaceReportOutputTarget(t);
//            }
            t.setOutputDestination(op.getID());
            resultsDAO.saveRaceReportOutputTarget(t);
        });
        
        if (t.outputDestination() == null) destinationChoiceBox.getSelectionModel().selectFirst();
        else destinationChoiceBox.getSelectionModel().select(t.outputDestination());
        destinationChoiceBox.setPrefWidth(150);
        destinationChoiceBox.setMaxWidth(150);
        
        // TextField for the filename
        TextField filename = new TextField();
        filename.setText(t.getOutputFilename());
        filename.setPrefWidth(200);
        filename.setMaxWidth(400);
        
        filename.textProperty().addListener((observable, oldValue, newValue) -> {
            t.setOutputFilename(newValue);
            resultsDAO.saveRaceReportOutputTarget(t);    
        });
        
        // Remove 
        
        Button remove = new Button("Remove");
        remove.setOnAction((ActionEvent e) -> {
            removeRaceReportOutputTarget(t);
        });
        
        rotHBox.getChildren().addAll(destinationChoiceBox,filename,remove);
        // Add the rotVBox to the outputTargetsVBox
        rotHBoxMap.put(t, rotHBox);
        outputTargetsVBox.getChildren().add(rotHBox);
       
    }
 
Example 12
Source File: LinkSliderWidget.java    From BowlerStudio with GNU General Public License v3.0 4 votes vote down vote up
public LinkSliderWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR d) {

		this.linkIndex = linkIndex;
		this.device = d;
		if (DHParameterKinematics.class.isInstance(device)) {
			dhdevice = (DHParameterKinematics) device;
		}

		abstractLink = device.getAbstractLink(linkIndex);

		TextField name = new TextField(abstractLink.getLinkConfiguration().getName());
		name.setMaxWidth(100.0);
		name.setOnAction(event -> {
			abstractLink.getLinkConfiguration().setName(name.getText());
		});

		setSetpoint(new EngineeringUnitsSliderWidget(this, abstractLink.getMinEngineeringUnits(),
				abstractLink.getMaxEngineeringUnits(), device.getCurrentJointSpaceVector()[linkIndex], 180,
				dhlink.getLinkType() == DhLinkType.ROTORY ? "degrees" : "mm"));

		GridPane panel = new GridPane();

		panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1
																		// is 75
																		// wide
		panel.getColumnConstraints().add(new ColumnConstraints(120)); // column
																		// 1 is
																		// 75
																		// wide
		panel.getColumnConstraints().add(new ColumnConstraints(120)); // column
																		// 2 is
																		// 300
																		// wide

		panel.add(new Text("#" + linkIndex), 0, 0);
		panel.add(name, 1, 0);
		panel.add(getSetpoint(), 2, 0);

		getChildren().add(panel);
		abstractLink.addLinkListener(this);
		// device.addJointSpaceListener(this);

	}
 
Example 13
Source File: DHLinkWidget.java    From BowlerStudio with GNU General Public License v3.0 4 votes vote down vote up
public DHLinkWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR device2, Button del,IOnEngineeringUnitsChange externalListener, MobileBaseCadManager manager ) {

		this.linkIndex = linkIndex;
		this.device = device2;
		if(DHParameterKinematics.class.isInstance(device2)){
			dhdevice=(DHParameterKinematics)device2;
		}
		this.del = del;
		AbstractLink abstractLink  = device2.getAbstractLink(linkIndex);
		
		
		TextField name = new TextField(abstractLink.getLinkConfiguration().getName());
		name.setMaxWidth(100.0);
		name.setOnAction(event -> {
			abstractLink.getLinkConfiguration().setName(name.getText());
		});
		
		setpoint = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() {
			
			@Override
			public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,
					double newAngleDegrees) {
	    		try {
					device2.setDesiredJointAxisValue(linkIndex, setpoint.getValue(), 2);
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				};
			}
		}, 
		abstractLink.getMinEngineeringUnits(), 
		abstractLink.getMaxEngineeringUnits(), 
		device2.getCurrentJointSpaceVector()[linkIndex], 
		180,dhlink.getLinkType()==DhLinkType.ROTORY?"degrees":"mm");
		
		
		
		final Accordion accordion = new Accordion();

		if(dhdevice!=null)
			accordion.getPanes().add(new TitledPane("Configure D-H", new DhSettingsWidget(dhdevice.getChain().getLinks().get(linkIndex),dhdevice,externalListener)));
		accordion.getPanes().add(new TitledPane("Configure Link", new LinkConfigurationWidget(abstractLink.getLinkConfiguration(), device2.getFactory(),setpoint,manager)));
		
		GridPane panel = new GridPane();
		
		panel.getColumnConstraints().add(new ColumnConstraints(80)); // column 1 is 75 wide
		panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1 is 75 wide
		panel.getColumnConstraints().add(new ColumnConstraints(120)); // column 2 is 300 wide
		
		
		panel.add(	del, 
				0, 
				0);
		panel.add(	new Text("#"+linkIndex), 
				1, 
				0);
		panel.add(	name, 
				2, 
				0);
		panel.add(	setpoint, 
				3, 
				0);
		panel.add(	accordion, 
				2, 
				1);

		getChildren().add(panel);
	}
 
Example 14
Source File: SiteListStage.java    From dm3270 with Apache License 2.0 4 votes vote down vote up
public SiteListStage (Preferences prefs, String key, int max, boolean show3270e)
{
  super (prefs);

  setTitle ("Site Manager");

  readPrefs (key, max);

  fields.add (new PreferenceField (key + " name", 150, Type.TEXT));
  fields.add (new PreferenceField ("URL", 150, Type.TEXT));
  fields.add (new PreferenceField ("Port", 50, Type.NUMBER));
  fields.add (new PreferenceField ("Ext", 50, Type.BOOLEAN));
  fields.add (new PreferenceField ("Model", 40, Type.NUMBER));
  fields.add (new PreferenceField ("Plugins", 50, Type.BOOLEAN));
  fields.add (new PreferenceField ("Save folder", 80, Type.TEXT));

  VBox vbox = getHeadings ();

  // input fields
  for (Site site : sites)
  {
    HBox hbox = new HBox ();
    hbox.setSpacing (5);
    hbox.setPadding (new Insets (0, 5, 0, 5));    // trbl

    for (int i = 0; i < fields.size (); i++)
    {
      PreferenceField field = fields.get (i);
      if (field.type == Type.TEXT || field.type == Type.NUMBER)
      {
        TextField textField = site.getTextField (i);
        textField.setMaxWidth (field.width);
        hbox.getChildren ().add (textField);
      }
      else if (field.type == Type.BOOLEAN)
      {
        HBox box = new HBox ();
        CheckBox checkBox = site.getCheckBoxField (i);
        box.setPrefWidth (field.width);
        box.setAlignment (Pos.CENTER);
        box.getChildren ().add (checkBox);
        hbox.getChildren ().add (box);
      }
    }
    vbox.getChildren ().add (hbox);
  }

  BorderPane borderPane = new BorderPane ();
  borderPane.setCenter (vbox);
  borderPane.setBottom (buttons ());

  Scene scene = new Scene (borderPane);
  setScene (scene);

  saveButton.setOnAction (e -> save (key));
  cancelButton.setOnAction (e -> this.hide ());
  editListButton.setOnAction (e -> this.show ());
}