Here's a quick example using a styled MenuButton
.
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class WordLikeMenuButton extends Application {
@Override
public void start(Stage primaryStage) {
MenuButton menuButton = new MenuButton();
menuButton.getItems().addAll(
Stream.of("Info", "New", "Open", "Save", "Save As", "Print", "Share", "Export", "Close")
.map(MenuItem::new).collect(Collectors.toList()));
BorderPane root = new BorderPane(null, menuButton, null, null, null);
Scene scene = new Scene(root, 350, 75);
scene.getStylesheets().add("word-like-menu-button.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
word-like-menu-button.css:
.menu-button, .menu-button .menu-item, .menu-button .context-menu {
-fx-background-color: #28559c;
}
.menu-button .menu-item:hover {
-fx-background-color: #3b6bb7 ;
}
.menu-button .menu-item .label {
-fx-text-fill: white ;
}
.menu-button > .arrow-button {
-fx-background-color: white, #28559c ;
-fx-background-insets: 1, 3 ;
-fx-background-radius: 16, 16 ;
-fx-padding: 8 ;
}
.menu-button > .arrow-button > .arrow {
-fx-background-color: white ;
/*-fx-background-insets: 0, 2 ;
-fx-background-radius: 12, 12 ;*/
-fx-padding: 8 ;
-fx-shape: "M0 6 l-6 -6 l0 -2 l6 -6 l2 0 l-6 6 l12 0 l0 2 l-12 0 l6 6 z";
}
This gives
MenuButton
. To get it to look the same way as your image, you would need to apply some CSS. – Barcarole