Java Code Examples for javafx.scene.control.Button#setMinSize()

The following examples show how to use javafx.scene.control.Button#setMinSize() . 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: ToolbarHandler.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Add a custom tool bar item
 *  @param icon Icon {@link Image}
 *  @param tool_tip Tool tip text
 *  @return {@link Button}
 */
public Button addItem(final ImageView icon, final String tool_tip)
{
    if (!have_custom_items)
    {
        toolbar.getItems().add(new Separator());
        have_custom_items = true;
    }
    final Button item = new Button();
    item.setGraphic(icon);
    item.setTooltip(new Tooltip(tool_tip));

    // Buttons should size based on the icon, but
    // without explicit size, they sometimes start out zero-sized.
    // setMinSize tends to have icon end up in top-left corner.
    // setPrefSize tends to show just the icon, no button.
    // minSize with visible button is better than no button.
    // Icon gets positioned once the button is pressed.
    item.setMinSize(BUTTON_WIDTH, BUTTON_HEIGHT);
    toolbar.getItems().add(item);
    return item;
}
 
Example 2
Source File: StateCell.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private Button createButton(final String icon, final String tooltip, final ScanAction action)
{
    final Button button = new Button();
    button.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);
    button.setPrefHeight(20);
    button.setGraphic(ImageCache.getImageView(StateCell.class, icon));
    button.setTooltip(new Tooltip(tooltip));
    button.setOnAction(event ->
    {
        try
        {
            action.perform(getTableRow().getItem().id.get());
        }
        catch (Exception ex)
        {
            logger.log(Level.WARNING, "Failed: " + tooltip, ex);
        }
    });
    return button;
}
 
Example 3
Source File: BoolButtonRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ButtonBase createJFXNode() throws Exception
{
    led = new Ellipse();
    led.getStyleClass().add("led");
    button = new Button("BoolButton", led);
    button.getStyleClass().add("action_button");
    button.setMnemonicParsing(false);

    // Model has width/height, but JFX widget has min, pref, max size.
    // updateChanges() will set the 'pref' size, so make min use that as well.
    button.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);

    // Fix initial layout
    toolkit.execute(() -> Platform.runLater(button::requestLayout));

    if (! toolkit.isEditMode())
    {
        if (model_widget.propMode().getValue() == Mode.TOGGLE)
            button.setOnAction(event -> handlePress(true));
        else
        {
            final boolean inverted = model_widget.propMode().getValue() == Mode.PUSH_INVERTED;
            button.setOnMousePressed(event -> handlePress(! inverted));
            button.setOnMouseReleased(event -> handlePress(inverted));
        }
    }

    return button;
}
 
Example 4
Source File: ToolbarHandler.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void addUndo(final boolean active)
{
    final Button[] buttons = UndoButtons.createButtons(plot.getUndoableActionManager());
    for (Button button : buttons)
        button.setMinSize(BUTTON_WIDTH, BUTTON_HEIGHT);
    toolbar.getItems().addAll(buttons);
}
 
Example 5
Source File: ImageToolbarHandler.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Add a custom tool bar item
 *  @param icon Icon {@link Image}
 *  @param tool_tip Tool tip text
 *  @return {@link ToolItem}
 */
public Button addItem(final Image icon, final String tool_tip)
{
    if (!have_custom_items)
    {
        toolbar.getItems().add(new Separator());
        have_custom_items = true;
    }
    final Button item = new Button();
    item.setGraphic(new ImageView(icon));
    item.setTooltip(new Tooltip(tool_tip));
    item.setMinSize(ToolbarHandler.BUTTON_WIDTH, ToolbarHandler.BUTTON_HEIGHT);
    toolbar.getItems().add(item);
    return item;
}
 
Example 6
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Button createToolbarButton(final String id, final String tool_tip, final EventHandler<ActionEvent> handler)
{
    final Button button = new Button();
    try
    {
        // Icons are not centered inside the button until the
        // button is once pressed, or at least focused via "tab"
        button.setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/" + id + ".png"));

        // Using the image as a background like this centers the image,
        // but replaces the complete characteristic button outline with just the icon.
        // button.setBackground(new Background(new BackgroundImage(new Image(Activator.getIcon(id)),
        //                      BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
        //                      BackgroundPosition.CENTER,
        //                      new BackgroundSize(16, 16, false, false, false, false))));
        button.setTooltip(new Tooltip(tool_tip));
    }
    catch (Exception ex)
    {
        logger.log(Level.WARNING, "Cannot load icon for " + id, ex);
        button.setText(tool_tip);
    }
    // Without defining the button size, the buttons may start out zero-sized
    // until they're first pressed/tabbed
    button.setMinSize(35, 25);
    button.setOnAction(handler);

    // Forcing a layout of the button on later UI ticks
    // tends to center the image
    Platform.runLater(() -> Platform.runLater(button::requestLayout));

    return button;
}
 
Example 7
Source File: CPopupButton.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Node getNode(
		PageActionManager actionmanager,
		CPageData inputdata,
		Window parentwindow,
		TabPane[] parenttabpanes,
		CollapsibleNode nodetocollapsewhenactiontriggered) {
	Button button = new Button(label);
	button.setStyle("-fx-base: #ffffff; -fx-hover-base: #ddeeff;");
	Label hamburgerlabel = new Label("\u2630");
	hamburgerlabel.setFont(Font.font(hamburgerlabel.getFont().getFamily(), FontWeight.THIN,
			hamburgerlabel.getFont().getSize() * 0.5f));
	button.setGraphic(hamburgerlabel);
	button.setContentDisplay(ContentDisplay.RIGHT);
	button.setMinSize(Button.USE_PREF_SIZE, Button.USE_PREF_SIZE);
	button.textOverrunProperty().set(OverrunStyle.CLIP);
	if (rollovertip != null)
		if (rollovertip.length() > 0)
			button.setTooltip(new Tooltip(rollovertip));

	// --------- setup popup window

	button.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {

			try {
				CPopupButton.generateAndShowPopup(button,
						payload.getNode(actionmanager, inputdata, parentwindow, new TabPane[0],nodetocollapsewhenactiontriggered), inputdata,
						parentwindow, allowscroll, showunderwidget);
			} catch (Exception e) {
				logger.severe("Unexpected exception " + e.getMessage());
				for (int i = 0; i < e.getStackTrace().length; i++)
					logger.severe("   + " + e.getStackTrace()[i].toString());
			}
		}
	});

	// ------------------------

	return button;
}
 
Example 8
Source File: CActionButton.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Node getNode(
		PageActionManager actionmanager,
		CPageData inputdata,
		Window parentwindow,
		TabPane[] parenttabpanes,
		CollapsibleNode nodetocollapsewhenactiontriggered) {

	if (this.conditionalshow) {
		DataElt thiselement = inputdata.lookupDataElementByName(conditionalshowdatareference.getName());
		if (thiselement == null)
			throw new RuntimeException(String.format(
					"could not find any page data with name = %s" + conditionalshowdatareference.getName()));
		if (!thiselement.getType().equals(conditionalshowdatareference.getType()))
			throw new RuntimeException(
					String.format("page data with name = %s does not have expected %s type, actually found %s",
							conditionalshowdatareference.getName(), conditionalshowdatareference.getType(),
							thiselement.getType()));
		ChoiceDataElt<?> thischoiceelement = (ChoiceDataElt<?>) thiselement;
		if (thischoiceelement.getStoredValue().compareTo("YES") != 0)
			return new Label("");
	}

	button = new Button(label);
	button.setStyle("-fx-base: #ffffff; -fx-hover-base: #ddeeff;");
	button.setMinSize(Button.USE_PREF_SIZE, Button.USE_PREF_SIZE);
	button.textOverrunProperty().set(OverrunStyle.CLIP);
	// button.setMinWidth((new
	// Text(this.label).getBoundsInLocal().getWidth()+20)*1.3);
	if (tooltip != null)
		button.setTooltip(new Tooltip("tooltip"));
	if (!this.hasconfirmationmessage) {
		if (action != null) {
			actionmanager.registerEvent(button, action);
			if (callback != null)
				actionmanager.registerCallback(button, callback);
			buttonhandler = new ButtonHandler(actionmanager);
			button.setOnMouseClicked(buttonhandler);
		}
		if (inlineaction != null) {
			if (nodetocollapsewhenactiontriggered != null)
				inlineaction.setNodeToCollapse(nodetocollapsewhenactiontriggered);
			if (this.forcepopuphidewheninline) {
				actionmanager.registerInlineActionwithPopupClose(button, inlineaction);
			} else {
				actionmanager.registerInlineAction(button, inlineaction);
			}
			buttonhandler = new ButtonHandler(actionmanager);
			button.setOnMouseClicked(buttonhandler);
		}
	}
	if (this.hasconfirmationmessage) {
		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent arg0) {
				Alert alert = new Alert(AlertType.CONFIRMATION);
				alert.setTitle("User Confirmation");
				alert.setContentText(confirmationmessage);
				ButtonType continuetype = new ButtonType(confirmationmessagecontinuelabel);
				ButtonType stoptype = new ButtonType(confirmationmessagestoplabel);
				alert.getButtonTypes().setAll(continuetype, stoptype);
				Optional<ButtonType> result = alert.showAndWait();
				if (result.get() == continuetype) {

					if (action != null) {
						if (callback != null)
							actionmanager.directfireEvent(action, callback);
						if (callback == null)
							actionmanager.directfireEvent(action);
					}
					if (inlineaction != null) {
						if (forcepopuphidewheninline)
							inlineaction.forcePopupClose();
						actionmanager.directfireInlineEvent(inlineaction);
					}
				}

			}

		});
	}

	return button;
}