I started to style one of my applications and I noticed something weird. This is an example that reflects that behavior. As you may notice, there is a menu with three items. I styled context menu (orange), but it appears that context menu is in some other wider container that holds it. What is that container and how it can be styled to get natural looking menu.
Here is a code too:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class TestMenu extends Application {
@Override
public void start(Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("File");
MenuItem menuItemSettings = new MenuItem("Settings");
MenuItem menuItemOpen = new MenuItem("Open");
MenuItem menuItemFile = new MenuItem("Exit");
TextField textField = new TextField();
textField.setPrefColumnCount(25);
menuBar.getMenus().addAll(menu);
menu.getItems().addAll(menuItemSettings, menuItemOpen, menuItemFile);
borderPane.setTop(menuBar);
borderPane.setCenter(textField);
Scene scene = new Scene(borderPane, 320, 200);
scene.getStylesheets().addAll("/testcss/style.css");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
And stylesheet:
.root {
-fx-background-color: #222;
}
.text {
-fx-fill: white;
}
.menu-bar {
-fx-background-color: #007fa8;
}
.menu-item {
-fx-background-color: #222;
}
.menu-item:hover {
-fx-background-color: #3399B9;
}
.menu-item:pressed {
-fx-background-color: #004C65;
}
.context-menu {
-fx-background-color: orange;
}
Thanks in advance.