Java Code Examples for javafx.scene.control.ComboBox#setPrefWidth()

The following examples show how to use javafx.scene.control.ComboBox#setPrefWidth() . 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: TimelinePanel.java    From constellation with Apache License 2.0 5 votes vote down vote up
private ComboBox<String> createComboNodeLabels() {
    final ComboBox<String> newComboBox = new ComboBox<>();
    newComboBox.setPrefWidth(150.0);
    newComboBox.setVisible(false);
    newComboBox.setPromptText(Bundle.SelectLabelAttribute());
    newComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (oldValue == null && newValue != null) {
            coordinator.setNodeLabelsAttr(newValue);
        } else if (oldValue != null && newValue != null && !oldValue.equals(newValue)) {
            coordinator.setNodeLabelsAttr(newValue);
        }
    });

    //scroll on button only not drop downlist.
    newComboBox.setOnScroll(t -> {
        if (t.getDeltaY() < 0) {
            newComboBox.getSelectionModel().selectNext();
        } else if (t.getDeltaY() > 0) {

            newComboBox.getSelectionModel().selectPrevious();
        }
    });

    newComboBox.setVisibleRowCount(5);

    return newComboBox;
}
 
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: SelectableTitledPaneDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override 
	public void start(Stage stage) {
	        
		  List<String> list = new ArrayList<>(Arrays.asList(strs));
		  	  
//		  ComboBox<?> combo = ComboBoxBuilder.create().
//		            prefWidth(150).
//		            //items(list).
//		            items(FXCollections.observableArrayList(list)).//"aa", "bb", "bb")); 		  
//		            //promptText(resourceBundle.getString("search.prompt.owner")).
//		            promptText("Choice").
//		            build();
		 
		  ComboBox<String> combo = new ComboBox<String>();
		  combo.setItems(FXCollections.observableArrayList(list));
		  combo.setPrefWidth(150);
		  combo.setPromptText("Choice");

		  //combo.setItems((ObservableList<?>) FXCollections.observableArrayList(list));//"aa", "bb", "bb"));
		  
		  
		  SelectableTitledPane ownerParams = new SelectableTitledPane(
				  //resourceBundle.getString("search.checkbox.owner"),
				  "checkbox",
				  combo);

	        
	        StackPane pane = new StackPane();
	        pane.setBackground(null);
	        pane.setPadding(new Insets(10, 10, 10, 10));
	        pane.getChildren().addAll( ownerParams);

	        Scene scene = new Scene(pane);
	        stage.setScene(scene);
	        stage.show();
	    }
 
Example 4
Source File: DisplayEditor.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private ToolBar createToolbar()
{
    final Button[] undo_redo = UndoButtons.createButtons(undo);

    final ComboBox<String> zoom_levels = new ComboBox<>();
    zoom_levels.getItems().addAll(JFXRepresentation.ZOOM_LEVELS);
    zoom_levels.setEditable(true);
    zoom_levels.setValue(JFXRepresentation.DEFAULT_ZOOM_LEVEL);
    zoom_levels.setTooltip(new Tooltip(Messages.SelectZoomLevel));
    zoom_levels.setPrefWidth(100.0);
    // For Ctrl-Wheel zoom gesture
    zoomListener zl = new zoomListener(zoom_levels);
    toolkit.setZoomListener(zl);
    zoom_levels.setOnAction(event ->
    {
        final String before = zoom_levels.getValue();
        if (before == null)
            return;
        final String actual = requestZoom(before);
        // Java 9 results in IndexOutOfBoundException
        // when combo is updated within the action handler,
        // so defer to another UI tick
        Platform.runLater(() ->
            zoom_levels.setValue(actual));
    });

    final MenuButton order = new MenuButton(null, null,
        createMenuItem(ActionDescription.TO_BACK),
        createMenuItem(ActionDescription.MOVE_UP),
        createMenuItem(ActionDescription.MOVE_DOWN),
        createMenuItem(ActionDescription.TO_FRONT));
    order.setTooltip(new Tooltip(Messages.Order));

    final MenuButton align = new MenuButton(null, null,
        createMenuItem(ActionDescription.ALIGN_LEFT),
        createMenuItem(ActionDescription.ALIGN_CENTER),
        createMenuItem(ActionDescription.ALIGN_RIGHT),
        createMenuItem(ActionDescription.ALIGN_TOP),
        createMenuItem(ActionDescription.ALIGN_MIDDLE),
        createMenuItem(ActionDescription.ALIGN_BOTTOM),
        createMenuItem(ActionDescription.ALIGN_GRID));
    align.setTooltip(new Tooltip(Messages.Align));

    final MenuButton size = new MenuButton(null, null,
        createMenuItem(ActionDescription.MATCH_WIDTH),
        createMenuItem(ActionDescription.MATCH_HEIGHT));
    size.setTooltip(new Tooltip(Messages.Size));

    final MenuButton dist = new MenuButton(null, null,
        createMenuItem(ActionDescription.DIST_HORIZ),
        createMenuItem(ActionDescription.DIST_VERT));
    dist.setTooltip(new Tooltip(Messages.Distribute));

    // Use the first item as the icon for the drop-down...
    try
    {
        order.setGraphic(ImageCache.getImageView(ActionDescription.TO_BACK.getIconResourcePath()));
        align.setGraphic(ImageCache.getImageView(ActionDescription.ALIGN_LEFT.getIconResourcePath()));
        size.setGraphic(ImageCache.getImageView(ActionDescription.MATCH_WIDTH.getIconResourcePath()));
        dist.setGraphic(ImageCache.getImageView(ActionDescription.DIST_HORIZ.getIconResourcePath()));
    }
    catch (Exception ex)
    {
        logger.log(Level.WARNING, "Cannot load icon", ex);
    }


    return new ToolBar(
        grid = createToggleButton(ActionDescription.ENABLE_GRID),
        snap = createToggleButton(ActionDescription.ENABLE_SNAP),
        coords = createToggleButton(ActionDescription.ENABLE_COORDS),
        new Separator(),
        order,
        align,
        size,
        dist,
        new Separator(),
        undo_redo[0],
        undo_redo[1],
        new Separator(),
        zoom_levels);
}
 
Example 5
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);
       
    }