javafx.scene.control.MenuItem.setGraphic()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中javafx.scene.control.MenuItem.setGraphic()方法的一些代码示例,展示了MenuItem.setGraphic()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setGraphic()方法的具体详情如下:
包路径:javafx.scene.control.MenuItem
类名称:MenuItem
方法名:setGraphic

暂无

代码示例

代码示例来源:origin: speedment/speedment

/**
 * Adds a new {@link MenuItem} factory to the end of this handler.
 *
 * @param text    the text to show
 * @param icon    the icon to show
 * @param action  the action to perform when the button is pressed
 * @return        this instance
 */
default MenuBarTabHandler addMenuItem(String text, SpeedmentIcon icon, EventHandler<ActionEvent> action) {
  return set(text.replace("_", "").replace(" ", "-").toLowerCase(), () -> {
    final MenuItem item = new MenuItem(text);
    item.setGraphic(icon.view());
    item.setOnAction(action);
    return item;
  });
}

代码示例来源:origin: de.jensd/fontawesomefx-common

public void setIcon(MenuItem menuItem, GlyphIcons icon, String fontSize, String iconSize) {
  if (menuItem == null) {
    throw new IllegalArgumentException("The menu item must not be 'null'!");
  }
  Text label = createIcon(icon, iconSize);
  menuItem.setStyle("-fx-font-size: " + fontSize);
  menuItem.setGraphic(label);
}

代码示例来源:origin: io.github.factoryfx/javafxDataEditing

public void addIcon(MenuItem component, FontAwesome.Glyph icon) {
  if (icon != null) {
    component.setGraphic(getFontAwesome().create(icon).color(Color.BLACK));
  }
}

代码示例来源:origin: com.nexitia.emaginplatform/emagin-jfxcore-engine

/**
  * Generates an hyperlink from a component
  *
  * @param controller
  * @param actionDefinition
  * @return Button
  */
 public static MenuItem menuItemFrom(final AbstractViewController controller, final VLViewComponentXML actionDefinition) {

  final MenuItem menuItem = new MenuItem();
  menuItem.setId(actionDefinition.getId());

  final String title = actionDefinition.getPropertyValue(XMLConstants.LABEL);
  if (!StringUtils.isEmpty(title)) {
   menuItem.setText(controller.getLocalised(title));
  }

  Label label = new Label();
  IconUtils.setIcon(label, actionDefinition);
  menuItem.setGraphic(label);

  setOnAction(actionDefinition, menuItem, controller);
  return menuItem;
 }
}

代码示例来源:origin: org.drombler.commons/drombler-commons-action-fx

/**
 * Configures a {@link MenuItem} with the specified action.
 *
 * @param menuItem the menu item to configre
 * @param action the action
 * @param iconSize the icon size
 */
public static void configureMenuItem(MenuItem menuItem, FXAction action, int iconSize) {
  menuItem.setMnemonicParsing(true);
  menuItem.textProperty().bind(action.displayNameProperty());
  menuItem.acceleratorProperty().bind(action.acceleratorProperty());
  menuItem.setOnAction(action);
  menuItem.disableProperty().bind(action.enabledProperty().not());
  if (action.getGraphicFactory() != null) {
    Node graphic = action.getGraphicFactory().createGraphic(iconSize);
    if (graphic != null) {
      menuItem.setGraphic(graphic);
    }
  }
}

相关文章