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

The following examples show how to use javafx.scene.control.TextField#setPrefColumnCount() . 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: DemoPane.java    From FxDock with Apache License 2.0 6 votes vote down vote up
private static void a(Pane p, int gap, double ... specs)
{
	HPane hp = new HPane(2);
	int ix = 0;
	for(double w: specs)
	{
		Color c = Color.gray(0.5 + 0.5 * ix / (specs.length - 1));
		String text = DemoTools.spec(w);
		TextField t = new TextField(text);
		t.setEditable(false);
		t.setPrefColumnCount(3);
		t.setBackground(FX.background(c));
		t.setPadding(Insets.EMPTY);
		hp.add(t, w);
		ix++;
	}
	p.getChildren().add(hp);
}
 
Example 2
Source File: ListDoubleRangeComponent.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public ListDoubleRangeComponent() {
  inputField = new TextField();
  inputField.setPrefColumnCount(16);
  /*
   * inputField.getDocument().addDocumentListener(new DocumentListener() {
   * 
   * @Override public void changedUpdate(DocumentEvent e) { update(); }
   * 
   * @Override public void removeUpdate(DocumentEvent e) { update(); }
   * 
   * @Override public void insertUpdate(DocumentEvent e) { update(); } });
   */

  textField = new Label();
  // textField.setColumns(8);

  add(inputField, 0, 0);
  add(textField, 0, 1);
}
 
Example 3
Source File: ListDoubleComponent.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public ListDoubleComponent() {
  inputField = new TextField();
  inputField.setPrefColumnCount(16);

  /*
   * inputField.getDocument().addDocumentListener(new DocumentListener() {
   * 
   * @Override public void changedUpdate(DocumentEvent e) { update(); }
   * 
   * @Override public void removeUpdate(DocumentEvent e) { update(); }
   * 
   * @Override public void insertUpdate(DocumentEvent e) { update(); } });
   */

  textField = new Label();
  // textField.setColumns(8);

  add(inputField, 0, 0);
  add(textField, 0, 1);
}
 
Example 4
Source File: TomlEntryEditor.java    From Lipi with MIT License 6 votes vote down vote up
private void initValueTextControl(String value) {

        if (value.length() > 30) {
            TextArea valueTextArea = new TextArea(value);
            valueTextArea.setPrefColumnCount(16);

            int cols = value.length() / 30;
            valueTextArea.setPrefRowCount(cols);
//            valueTextArea.prefHeight(20);
            valueTextArea.setWrapText(true);
            valueTextControl = valueTextArea;
        } else {
            TextField valueTextField = new TextField(value);
            valueTextField.setPrefColumnCount(18);
            valueTextControl = valueTextField;

        }

    }
 
Example 5
Source File: DirectoryComponent.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the component.
 */
public DirectoryComponent() {

  // Create text field.
  txtDirectory = new TextField();
  txtDirectory.setPrefColumnCount(TEXT_FIELD_COLUMNS);
  txtDirectory.setFont(SMALL_FONT);

  // Chooser button.
  final Button btnFileBrowser = new Button("...");
  btnFileBrowser.setOnAction(e -> {
    // Create chooser.
    DirectoryChooser fileChooser = new DirectoryChooser();
    fileChooser.setTitle(TITLE);

    // Set current directory.
    final String currentPath = txtDirectory.getText();
    if (currentPath.length() > 0) {

      final File currentFile = new File(currentPath);
      final File currentDir = currentFile.getParentFile();
      if (currentDir != null && currentDir.exists()) {
        fileChooser.setInitialDirectory(currentDir);
      }
    }

    // Open chooser.
    File selectedFile = fileChooser.showDialog(null);
    if (selectedFile == null)
      return;
    txtDirectory.setText(selectedFile.getPath());

  });

  setCenter(txtDirectory);
  setRight(btnFileBrowser);
}
 
Example 6
Source File: Exercise_14_07.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create a GridPane and set its properties
	GridPane pane = new GridPane();
	pane.setPadding(new Insets(5, 5, 5, 5));
	pane.setHgap(5);
	pane.setVgap(5);

	// Place text fields containing a centered, 
	// randomly generated string of 0 or 1 in the pane
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			TextField text = new TextField();
			text.setPrefColumnCount(1);
			text.setText(String.valueOf((int)(Math.random() * 2)));
			pane.add(text, i, j);
			pane.setHalignment(text, HPos.CENTER);
			pane.setValignment(text, VPos.CENTER);
		}
	}

	// Create a scene and plane it in the stage
	Scene scene = new Scene(pane);
	primaryStage.setTitle("Exercise_14_07"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 7
Source File: Exercise_18_36.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	SierpinskiTrianglePane trianglePane = new SierpinskiTrianglePane();
	TextField tfOrder = new TextField();
	tfOrder.setOnAction(
		e -> trianglePane.setOrder(Integer.parseInt(tfOrder.getText())));
	tfOrder.setPrefColumnCount(4);
	tfOrder.setAlignment(Pos.BOTTOM_RIGHT);

	// Pane to hold label, text field, and a button
	HBox hBox = new HBox(10);
	hBox.getChildren().addAll(new Label("Enter an order: "), tfOrder);
	hBox.setAlignment(Pos.CENTER);

	BorderPane borderPane = new BorderPane();
	borderPane.setCenter(trianglePane);
	borderPane.setBottom(hBox);

	// Create a scene and place it in the stage
	Scene scene = new Scene(borderPane, 200, 210);
	primaryStage.setTitle("Exercise_18_36"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage

	scene.widthProperty().addListener(ov -> trianglePane.paint());
	scene.heightProperty().addListener(ov -> trianglePane.paint());
}
 
Example 8
Source File: PanelMenuBar.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Called in FilterPanel.java when the ShowRenamePanelEventHandler is invoked.
 * A renameableTextField is generated in which the user inputs the new panel name.
 */
public void initRenameableTextFieldAndEvents() {
    renameableTextField = new TextField();
    renameableTextField.setId(IdGenerator.getPanelRenameTextFieldId(panel.panelIndex));
    Platform.runLater(() -> {
        renameableTextField.requestFocus();
        renameableTextField.selectAll();
    });
    renameableTextField.setText(panelName);
    augmentRenameableTextField();
    buttonAndKeyboardEventHandler();
    renameableTextField.setPrefColumnCount(30);
}
 
Example 9
Source File: StringParameter.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TextField createEditingComponent() {
  TextField stringComponent = new TextField();
  stringComponent.setPrefColumnCount(inputsize);
  // stringComponent.setBorder(BorderFactory.createCompoundBorder(stringComponent.getBorder(),
  // BorderFactory.createEmptyBorder(0, 4, 0, 0)));
  return stringComponent;
}
 
Example 10
Source File: NeutralMassComponent.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public NeutralMassComponent() {

    add(new Label("m/z:"), 0, 0);

    ionMassField = new TextField();
    ionMassField.textProperty().addListener((observable, oldValue, newValue) -> {
      updateNeutralMass();
    });
    ionMassField.setPrefColumnCount(8);
    add(ionMassField, 1, 0);

    add(new Label("Charge:"), 2, 0);

    chargeField = new TextField();
    chargeField.textProperty().addListener((observable, oldValue, newValue) -> {
      updateNeutralMass();
    });
    chargeField.setPrefColumnCount(2);
    add(chargeField, 3, 0);

    add(new Label("Ionization type:"), 0, 1, 2, 1);
    ionTypeCombo =
        new ComboBox<IonizationType>(FXCollections.observableArrayList(IonizationType.values()));
    ionTypeCombo.setOnAction(e -> {
      updateNeutralMass();
    });
    add(ionTypeCombo, 2, 1, 2, 1);

    add(new Label("Calculated mass:"), 0, 2, 2, 1);

    neutralMassField = new TextField();
    neutralMassField.setPrefColumnCount(8);
    neutralMassField.setStyle("-fx-background-color: rgb(192, 224, 240);");
    neutralMassField.setEditable(false);
    add(neutralMassField, 2, 2, 2, 1);

  }
 
Example 11
Source File: MassListComponent.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public MassListComponent() {

    setHgap(5.0);

    lookupMenu = new ContextMenu();

    nameField = new TextField();
    nameField.setPrefColumnCount(15);

    lookupButton = new Button("Choose...");
    lookupButton.setOnAction(e -> {
      List<String> currentNames = getMassListNames();

      lookupMenu.getItems().clear();
      for (String name : currentNames) {
        MenuItem item = new MenuItem(name);
        item.setOnAction(e2 -> {
          nameField.setText(name);
        });
        lookupMenu.getItems().add(item);
      }
      final Bounds boundsInScreen = lookupButton.localToScreen(lookupButton.getBoundsInLocal());
      lookupMenu.show(lookupButton, boundsInScreen.getCenterX(), boundsInScreen.getCenterY());
//      lookupMenu.show(lookupButton, 0, 0);
    });

    getChildren().addAll(nameField, lookupButton);

  }
 
Example 12
Source File: WebModule.java    From WorkbenchFX with Apache License 2.0 4 votes vote down vote up
public WebModule(String name, MaterialDesignIcon icon, String url) {
  super(name, icon);
  this.url = url;

  // setup webview
  browser = new WebView();
  webEngine = browser.getEngine();

  // workaround since HTTP headers related to CORS, are restricted, see: https://bugs.openjdk.java.net/browse/JDK-8096797
  System.setProperty("sun.net.http.allowRestrictedHeaders", "true");

  // setup textfield for URL
  browserUrl = new TextField("Loading...");
  HBox.setHgrow(browserUrl, Priority.ALWAYS);
  browserUrl.setPrefColumnCount(Integer.MAX_VALUE); // make sure textfield takes up rest of space
  browserUrl.setEditable(false);

  // setup toolbar
  ToolbarItem back = new ToolbarItem(new MaterialDesignIconView(MaterialDesignIcon.CHEVRON_LEFT),
      event -> webEngine.executeScript("history.back()"));
  ToolbarItem forward = new ToolbarItem(new MaterialDesignIconView(MaterialDesignIcon.CHEVRON_RIGHT),
      event -> webEngine.executeScript("history.forward()"));
  ToolbarItem home = new ToolbarItem(new MaterialDesignIconView(MaterialDesignIcon.HOME),
      event -> webEngine.load(url));
  ToolbarItem reload = new ToolbarItem(new MaterialDesignIconView(MaterialDesignIcon.REFRESH),
      event -> webEngine.reload());
  getToolbarControlsLeft().addAll(back, forward, home, reload, new ToolbarItem(browserUrl));

  ToolbarItem increaseSize = new ToolbarItem(new Group(increaseFontIcon),
      event -> browser.setFontScale(browser.getFontScale() + FONT_SCALE_INCREMENT));
  ToolbarItem decreaseSize = new ToolbarItem(new Group(decreaseFontIcon),
      event -> browser.setFontScale(browser.getFontScale() - FONT_SCALE_INCREMENT));
  getToolbarControlsRight().addAll(increaseSize, decreaseSize);

  // update textfield with url every time the url of the webview changes
  webEngine.documentProperty().addListener(
      observable -> {
        Document document = webEngine.getDocument();
        if (!Objects.isNull(document) &&
            !Strings.isNullOrEmpty(document.getDocumentURI())) {
          browserUrl.setText(document.getDocumentURI());
        }
      });
}
 
Example 13
Source File: Palette.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Create UI elements
 *  @return Top-level Node of the UI
 */
@SuppressWarnings("unchecked")
public Node create()
{
    final VBox palette = new VBox();

    final Map<WidgetCategory, Pane> palette_groups = createWidgetCategoryPanes(palette);
    groups = palette_groups.values();
    createWidgetEntries(palette_groups);

    final ScrollPane palette_scroll = new ScrollPane(palette);
    palette_scroll.setHbarPolicy(ScrollBarPolicy.NEVER);
    palette_scroll.setFitToWidth(true);

    // TODO Determine the correct size for the main node
    // Using 2*PREFERRED_WIDTH was determined by trial and error
    palette_scroll.setMinWidth(PREFERRED_WIDTH + 12);
    palette_scroll.setPrefWidth(PREFERRED_WIDTH);

    // Copy the widgets, i.e. the children of each palette_group,
    // to the userData.
    // Actual children are now updated based on search by widget name
    palette_groups.values().forEach(group -> group.setUserData(new ArrayList<Node>(group.getChildren())));

    final TextField searchField = new ClearingTextField();
    searchField.setPromptText(Messages.SearchTextField);
    searchField.setTooltip(new Tooltip(Messages.WidgetFilterTT));
    searchField.setPrefColumnCount(9);
    searchField.textProperty().addListener( ( observable, oldValue, search_text ) ->
    {
        final String search = search_text.toLowerCase().trim();
        palette_groups.values().stream().forEach(group ->
        {
            group.getChildren().clear();
            final List<Node> all_widgets = (List<Node>)group.getUserData();
            if (search.isEmpty())
                group.getChildren().setAll(all_widgets);
            else
                group.getChildren().setAll(all_widgets.stream()
                                                      .filter(node ->
                                                      {
                                                         final String text = ((ToggleButton) node).getText().toLowerCase();
                                                         return text.contains(search);
                                                      })
                                                     .collect(Collectors.toList()));
        });
    });
    HBox.setHgrow(searchField, Priority.NEVER);

    final HBox toolsPane = new HBox(6);
    toolsPane.setAlignment(Pos.CENTER_RIGHT);
    toolsPane.setPadding(new Insets(6));
    toolsPane.getChildren().add(searchField);

    BorderPane paletteContainer = new BorderPane();
    paletteContainer.setTop(toolsPane);
    paletteContainer.setCenter(palette_scroll);

    return paletteContainer;
}
 
Example 14
Source File: DoubleRangeComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public DoubleRangeComponent(NumberFormat format) {

    setSpacing(8.0);

    minTxtField = new TextField();
    minTxtField.setPrefColumnCount(8);
    // minTxtField.setMinWidth(100.0);

    maxTxtField = new TextField();
    maxTxtField.setPrefColumnCount(8);
    // maxTxtField.setMinWidth(100.0);

    minusLabel = new Label(" - ");
    minusLabel.setMinWidth(15.0);

    getChildren().addAll(minTxtField, minusLabel, maxTxtField);

    setMinWidth(600.0);
    // setStyle("-fx-border-color: red");

    setNumberFormat(format);
  }
 
Example 15
Source File: Exercise_16_15.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Appliction class
public void start(Stage primaryStage) {
	// Set properties for combobox
	cbo.getItems().addAll("TOP", "BOTTOM", "LEFT", "RIGHT");
	cbo.setStyle("-fx-color: green");
	cbo.setValue("LEFT");

	// Create a text field
	TextField tfGap = new TextField("0");
	tfGap.setPrefColumnCount(3);

	// Create a hox to hold labels a text field and combo box
	HBox paneForSettings = new HBox(10);
	paneForSettings.setAlignment(Pos.CENTER);
	paneForSettings.getChildren().addAll(new Label("contentDisplay:"),
		cbo, new Label("graphicTextGap:"), tfGap);

	// Create an imageview
	ImageView image = new ImageView(new Image("image/grapes.gif"));

	// Label the image
	Label lblGrapes = new Label("Grapes", image);
	lblGrapes.setGraphicTextGap(0);

	// Place the image and its label in a stack pane
	StackPane paneForImage = new StackPane(lblGrapes);

	// Create and register handlers
	cbo.setOnAction(e -> {
		lblGrapes.setContentDisplay(setDisplay());
	});

	tfGap.setOnAction(e -> {
		lblGrapes.setGraphicTextGap(Integer.parseInt(tfGap.getText()));
	});

	// Place nodes in a border pane
	BorderPane pane = new BorderPane();
	pane.setTop(paneForSettings);
	pane.setCenter(paneForImage);

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 400, 200);
	primaryStage.setTitle("Exericse_16_15"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 16
Source File: FileNameComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public FileNameComponent(int textfieldcolumns, List<File> lastFiles, FileSelectionType type) {
  // setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));

  this.type = type;

  txtFilename = new TextField();
  txtFilename.setPrefColumnCount(textfieldcolumns);
  txtFilename.setFont(smallFont);

  // last used files chooser button
  // on click - set file name to textField
  btnLastFiles = new LastFilesButton("last", file -> txtFilename.setText(file.getPath()));

  Button btnFileBrowser = new Button("...");
  btnFileBrowser.setOnAction(e -> {
    // Create chooser.
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select file");

    // Set current directory.
    final String currentPath = txtFilename.getText();
    if (currentPath.length() > 0) {

      final File currentFile = new File(currentPath);
      final File currentDir = currentFile.getParentFile();
      if (currentDir != null && currentDir.exists()) {
        fileChooser.setInitialDirectory(currentDir);
      }
    }

    // Open chooser.
    File selectedFile = null;
    if(type == FileSelectionType.OPEN)
      selectedFile = fileChooser.showOpenDialog(null);
    else
      selectedFile = fileChooser.showSaveDialog(null);
    
    if (selectedFile == null)
      return;
    txtFilename.setText(selectedFile.getPath());
  });

  getChildren().addAll(txtFilename, btnLastFiles, btnFileBrowser);

  setLastFiles(lastFiles);
}
 
Example 17
Source File: PercentComponent.java    From mzmine3 with GNU General Public License v2.0 3 votes vote down vote up
public PercentComponent() {

    // setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
    percentField = new TextField();
    percentField.setPrefColumnCount(4);

    getChildren().addAll(percentField, new Label("%"));

  }
 
Example 18
Source File: MZToleranceComponent.java    From mzmine3 with GNU General Public License v2.0 3 votes vote down vote up
public MZToleranceComponent() {

    // setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));

    mzToleranceField = new TextField();
    mzToleranceField.setPrefColumnCount(12);


    ppmToleranceField = new TextField();
    ppmToleranceField.setPrefColumnCount(6);

    getChildren().addAll(mzToleranceField, new Label("m/z  or"), ppmToleranceField,
        new Label("ppm"));
  }
 
Example 19
Source File: RTToleranceComponent.java    From mzmine3 with GNU General Public License v2.0 3 votes vote down vote up
public RTToleranceComponent() {



    // setBorder(BorderFactory.createEmptyBorder(0, 9, 0, 0));

    toleranceField = new TextField();
    toleranceField.setPrefColumnCount(6);

    toleranceType = new ComboBox<String>(toleranceTypes);

    setCenter(toleranceField);
    setRight(toleranceType);

  }
 
Example 20
Source File: IntRangeComponent.java    From mzmine3 with GNU General Public License v2.0 3 votes vote down vote up
public IntRangeComponent() {

    // setBorder(BorderFactory.createEmptyBorder(0, 9, 0, 0));

    minTxtField = new TextField();
    minTxtField.setPrefColumnCount(8);

    maxTxtField = new TextField();
    maxTxtField.setPrefColumnCount(8);


    add(minTxtField, 0, 0);
    add(new Label(" - "), 1, 0);
    add(maxTxtField, 2, 0);
  }