CustomMenuItem

Hello,
Does anyone know how to change the "highlight" color of a CustomMenuItem?
The highlight color is the color that "surrounds" the menu item when I move the mouse over it to indicated that is has been "selected." Right now it's blue and I want to change it to red or another color.
Thanks

Hi,
Please find the below code if asking to change the background color of the menu item
Add a style class to the menu item.
MenuItem item = new MenuItem("First Item");
item.getStyleClass().add("myMenuItem");And in the style class..
.myMenuItem:focused {
     -fx-background: red;
     -fx-background-color: red;
     -fx-text-fill: gray;
.myMenuItem:focused .label {
    -fx-text-fill: blue;
}Check whether this can help you. Happy Coding !! :)

Similar Messages

  • Customize menu css

    I'm trying to change the background to a Menu inside a MenuBar. I was able to change the MenuItem's background, but there's this gap at the top and at the bottom of the menu which is still gray, and I can't seem to find a way to change it.
    This is my code
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.*;
    import javafx.stage.Stage;
    public class CustomizeMenu extends Application {
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        MenuBar mb = new MenuBar();
        Menu menuFile = new Menu("File");
        Menu menuView = new Menu("View");
        menuView.getItems().addAll(new CheckMenuItem("All"), new CheckMenuItem("None"));
        menuFile.getItems().addAll(new MenuItem("Open"), menuView, new MenuItem("Close"));
        mb.getMenus().add(menuFile);
        Group g = new Group(mb);
        Scene scene = new Scene(g, 400, 300);
        scene.getStylesheets().add(CustomizeMenu.class.getResource("custom-menu.css").toExternalForm());
        stage.setScene(scene);
        stage.show();
    }This is my css
    .menu  {
      -fx-background-color: blue;
      -fx-text-fill: white;
    .menu-item{
        -fx-background-color: blue;
    .menu-item .label {
      -fx-text-fill: white;
    .menu-item:focused .label {
      -fx-text-fill: white;
    }Any help would be much appreciated, thanks.

    ascuccimarra wrote:
    Thanks for your response David, that did the trick. Didn't even find a reference to it in caspian.css. This definitely seems something that could be improved. Hope this thread helps others.ContextMenuContent is inserted into the scene graph when the menu is rendered. Basically it seems belong to the skin. You can find out about this with ScenicView if you manage to get hold of the scene used by the ContextMenu popup (I could do this with a CustomMenuItem). Regarding the css, David simply used the classname as selector as documented in the css reference.

  • How to Get List Item in Custom Context Menu?

    Hi,
    I got this code from the net.
    <CustomAction Id="SPTest.CustomMenuItem.ButtonClicked"
    RegistrationType="ContentType"
    RegistrationId="0x0101"
    Location="EditControlBlock"
    ImageUrl="/_layouts/IMAGES/DOCLINK.GIF"
    Sequence="600"
    Title="Click Me!"
    Description="Shows an alert message for this content type."
    >
    <UrlAction Url="javascript:alert('Hello World!');" />
    </CustomAction>
    It creates a custom context menu. How can i get the selected item using that code..
    Sorry for the tons of question. SharePoint newbie here (5 weeks in SP), Hehhehe!

    If you can redirect your request on context.....you can try this line of code
    <UrlActionUrl=”~site/_layouts/ItemAudit.aspx?ID={ItemId}&amp;List={ListId}”/>
    The Idea is to send in query string parameter and get the ItemID in the Pageload Event of the page you want to redirect to.
    Other tokens that are available
    Token
    Replaced By
    ~site/
    SPContext.Current.Web.ServerRelativeUrl
    ~sitecollection/
    SPContext.Current.Site.ServerRelativeUrl
    {ItemId}
    item.ID.ToString()
    {ItemUrl}
    item.Url
    {SiteUrl}
    web.Url
    {ListId}
    list.ID.ToString(“B”)
    {RecurrenceId}
    item.RecurrenceID
    Srikant N , MCPD SharePoint Developer 2010

  • Size of MenuItem

    I am using MenuButton a lot. To have a nice layout I often make the size of the button larger as needed just for nice layout purposes. What I can't get right yet is the size of the menuitems in a menubutton. It really looks bad if you have a large MenuButton and you open the menu that the contents is very small compared the button above.
    Anyway to change this?

    This is not a good solution, but I could not come up with a good solution, so you can try this - at least it seems to work for me . . .
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.layout.*;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.*;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
    /** Sizes the drop down menu for a menu button to at least same width as the menu button */
    public class MenuButtonSizing extends Application {
      private static final String FROBOZZ = "Frobozz";
      private static final String ZORK    = "Zork";
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        final MenuButton menuButton = new MenuButton("XYZZY is the Magic Word");
        final Label selection = new Label();
        final VBox layout = new VBox(30);
        layout.getChildren().setAll(selection, menuButton);
        layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 50;");
        stage.setScene(new Scene(layout));
        stage.show();
        // for the sizing to work correctly, the SizingMenuItem must be created
        // for the menu button after the menu button has been shown.
        SizingMenuItem frobozzItem = new SizingMenuItem(menuButton, FROBOZZ);
        frobozzItem.setOnAction(new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent t) {
            selection.setText(FROBOZZ);
        MenuItem zorkItem = new MenuItem(ZORK);
        zorkItem.setOnAction(new EventHandler<ActionEvent>() {
          @Override public void handle(ActionEvent t) {
            selection.setText(ZORK);
        menuButton.getItems().setAll(
                frobozzItem,
                zorkItem
      class SizingMenuItem extends CustomMenuItem {
        static final double BUFFER_WIDTH = 14; // to account for the width of the padding around menu items.
        SizingMenuItem(final MenuButton menuButton, String string) {
          super();
          Text   text      = new Text(string);
          Double textWidth = text.getBoundsInParent().getWidth();
          Shape  padding = new Rectangle(
                  textWidth,
                  0,
                  menuButton.getWidth() - textWidth - BUFFER_WIDTH,
                  2
          padding.setFill(Color.TRANSPARENT);
          Label label = new Label(string, padding);
          label.setContentDisplay(ContentDisplay.RIGHT);
          label.setGraphicTextGap(0);
          setContent(label);
    }

  • Issue in theme changing

    I have a menu known as Themes in menubar. When i select any theme from that menu(Themes) the application scene color should change according to that theme. And it should update the theme value in property file. How to do it

    I'd use a ChoiceBox in a CustomMenuItem for your Themes menu in the menubar. You could then add a listener to the SelectionModel of the ChoiceBox. When the selection changes, set your theme and update the property file.

Maybe you are looking for