title: Adding a title to a JavaFX ContextMenu
body: <p>Is it possible to add a title to a JavaFX <code>TableView</code> <code>ContextMenu</code>?</p>
  
  <p>For now, I have added a <code>MenuItem</code> which I have marked disabled (via <code>menuTitle.setDisable(true)</code>), but that is rendered with some style settings (opacity) that I havent figured out how to override.</p>
  
  <p>Code sample - </p>
  
  <pre><code>import java.util.function.Function;
  import java.util.stream.IntStream;
  
  import javafx.application.Application;
  import javafx.beans.property.BooleanProperty;
  import javafx.beans.property.IntegerProperty;
  import javafx.beans.property.SimpleBooleanProperty;
  import javafx.beans.property.SimpleIntegerProperty;
  import javafx.beans.property.SimpleStringProperty;
  import javafx.beans.property.StringProperty;
  import javafx.beans.value.ObservableValue;
  import javafx.scene.Scene;
  import javafx.scene.control.CheckMenuItem;
  import javafx.scene.control.ContextMenu;
  import javafx.scene.control.MenuItem;
  import javafx.scene.control.SeparatorMenuItem;
  import javafx.scene.control.TableColumn;
  import javafx.scene.control.TableRow;
  import javafx.scene.control.TableView;
  import javafx.scene.layout.BorderPane;
  import javafx.stage.Stage;
  
  public class TableWithContextMenu extends Application {
  
      @Override
      public void start(Stage primaryStage) {
          TableView&lt;Item&gt; table = new TableView&lt;&gt;();
          table.getColumns().add(column("Item", Item::nameProperty));
          table.getColumns().add(column("Value", Item::valueProperty));
  
          BooleanProperty globalSelection = new SimpleBooleanProperty();
  
          table.setRowFactory(t -&gt; {
              TableRow&lt;Item&gt; row = new TableRow&lt;&gt;();
              ContextMenu contextMenu = new ContextMenu();
              MenuItem menuTitle = new MenuItem("Menu Title");
              menuTitle.setDisable(true);
  
              MenuItem item2 = new MenuItem("Do something else");
              item2.setOnAction(e -&gt; System.out.println("Do something else with " + row.getItem().getName()));
  
              CheckMenuItem item3 = new CheckMenuItem("Global selection");
              item3.selectedProperty().bindBidirectional(globalSelection);
  
              contextMenu.getItems().addAll(menuTitle, item2, new SeparatorMenuItem(), item3);
  
              row.emptyProperty().addListener((obs, wasEmpty, isEmpty) -&gt; {
                  if (isEmpty) {
                      row.setContextMenu(null);
                  } else {
                      row.setContextMenu(contextMenu);
                  }
              });
              return row ;
          });
  
          IntStream.rangeClosed(1, 25).mapToObj(i -&gt; new Item("Item "+i, i)).forEach(table.getItems()::add);
  
          primaryStage.setScene(new Scene(new BorderPane(table), 800, 600));
          primaryStage.show();
      }
  
      private &lt;S,T&gt; TableColumn&lt;S,T&gt; column(String title, Function&lt;S, ObservableValue&lt;T&gt;&gt; property) {
          TableColumn&lt;S,T&gt; col = new TableColumn&lt;&gt;(title);
          col.setCellValueFactory(cellData -&gt; property.apply(cellData.getValue()));
          return col ;
      }
  
      public static class Item {
          private final IntegerProperty value = new SimpleIntegerProperty();
          private final StringProperty name = new SimpleStringProperty();
  
          public Item(String name, int value) {
              setName(name);
              setValue(value);
          }
  
          public final IntegerProperty valueProperty() {
              return this.value;
          }
  
          public final int getValue() {
              return this.valueProperty().get();
          }
  
          public final void setValue(final int value) {
              this.valueProperty().set(value);
          }
  
          public final StringProperty nameProperty() {
              return this.name;
          }
  
          public final String getName() {
              return this.nameProperty().get();
          }
  
          public final void setName(final String name) {
              this.nameProperty().set(name);
          }
  
  
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>
  The solution posted below, works for this example. However, when dealing with multiple FXML, it doesnt work unless I clear out the style classes and then apply the custom style. I have posted my working code <a href="https://gist.github.com/darthninja1/7e9b086359808807eb7c" rel="nofollow">here</a> that demonstrates the issue.</p>