ADDITIONAL SYSTEM INFORMATION :
Linux/Windows/Mac
Java/JavaFX 17/20
A DESCRIPTION OF THE PROBLEM :
Opening a ContexMenu I encountered the behaviour that it inherits some styles form the button opening it. This seems to depend on the show() method used. If I use one taking a Node the button style is applied to the menu, if I use one with Window it is not ... it also seems that only -fx-font-... properties are inherited, not e.g. -fx-text-fill or others. Reproducible with Java/JavaFX 17 and 20 on Linux, Windows and Mac.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import javafx.application.Application;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class StyleTest extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
ContextMenu menu = new ContextMenu();
menu.getItems().add(new MenuItem("Should"));
menu.getItems().add(new MenuItem("not"));
menu.getItems().add(new MenuItem("be"));
menu.getItems().add(new MenuItem("large!"));
Button button = new Button("Open menu");
button.setStyle("-fx-font-size: 2em");
button.setOnAction(e -> menu.show(button, Side.RIGHT, 0, 0));
BorderPane root = new BorderPane(button);
root.setStyle("-fx-padding: 3em");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The font size of the menu items should be the same as when opening the context menu with show(primaryStage).
ACTUAL -
The font size is the same as on the button.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class StyleTest extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
ContextMenu menu = new ContextMenu();
menu.getItems().add(new MenuItem("Should"));
menu.getItems().add(new MenuItem("not"));
menu.getItems().add(new MenuItem("be"));
menu.getItems().add(new MenuItem("large!"));
Button button = new Button("Open menu");
button.setStyle("-fx-font-size: 2em");
button.setOnAction(e -> menu.show(button, Side.RIGHT, 0, 0));
BorderPane root = new BorderPane(button);
root.setStyle("-fx-padding: 3em");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use show(Window) to open the popup or override the font style for the style classes used in the popup.
FREQUENCY : always
Linux/Windows/Mac
Java/JavaFX 17/20
A DESCRIPTION OF THE PROBLEM :
Opening a ContexMenu I encountered the behaviour that it inherits some styles form the button opening it. This seems to depend on the show() method used. If I use one taking a Node the button style is applied to the menu, if I use one with Window it is not ... it also seems that only -fx-font-... properties are inherited, not e.g. -fx-text-fill or others. Reproducible with Java/JavaFX 17 and 20 on Linux, Windows and Mac.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import javafx.application.Application;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class StyleTest extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
ContextMenu menu = new ContextMenu();
menu.getItems().add(new MenuItem("Should"));
menu.getItems().add(new MenuItem("not"));
menu.getItems().add(new MenuItem("be"));
menu.getItems().add(new MenuItem("large!"));
Button button = new Button("Open menu");
button.setStyle("-fx-font-size: 2em");
button.setOnAction(e -> menu.show(button, Side.RIGHT, 0, 0));
BorderPane root = new BorderPane(button);
root.setStyle("-fx-padding: 3em");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The font size of the menu items should be the same as when opening the context menu with show(primaryStage).
ACTUAL -
The font size is the same as on the button.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class StyleTest extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
ContextMenu menu = new ContextMenu();
menu.getItems().add(new MenuItem("Should"));
menu.getItems().add(new MenuItem("not"));
menu.getItems().add(new MenuItem("be"));
menu.getItems().add(new MenuItem("large!"));
Button button = new Button("Open menu");
button.setStyle("-fx-font-size: 2em");
button.setOnAction(e -> menu.show(button, Side.RIGHT, 0, 0));
BorderPane root = new BorderPane(button);
root.setStyle("-fx-padding: 3em");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use show(Window) to open the popup or override the font style for the style classes used in the popup.
FREQUENCY : always