-
Bug
-
Resolution: Fixed
-
P4
-
8u20
-
Java 8u-dev repo tip, Linux
In our software we have a number of ContextMenus whose items are rebuilt quite often. Some of these ContextMenus cause CSS warning to be logged to our console when they are used.
I have managed to track this issue down. It happens when a sub menu has been re-added to a ContextMenu and then shown a second time.
To reproduce:
1. Run the provided test class.
2. Right click on the label in the stage to show the context menu. Mouse over the sub menu to display it.
3. Click on the "Rebuild" button which will clear the context menu items and re add the sub menu.
4. Repeat step 2.
The second time the sub menu is show the following CSS warning will be printed to the console:
May 07, 2014 5:20:40 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.menu-item>*.label' in stylesheet jar:file:/home/csmith/dev/openjfx/build/sdk/rt/lib/ext/jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
May 07, 2014 5:20:40 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.menu-item>*.label' in stylesheet jar:file:/home/csmith/dev/openjfx/build/sdk/rt/lib/ext/jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
Ocassionally this submenu also displays with a fully transparent background which might be related to these warnings...
******************************************** Test Class ***************************************************
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class CustomMenuItemTest extends Application {
@Override public void start(final Stage primaryStage) throws Exception {
primaryStage.centerOnScreen();
primaryStage.setHeight(350);
primaryStage.setWidth(500);
final Menu submenu = new Menu("Sub Menu");
submenu.getItems().add(new MenuItem("Test 1"));
Label contextMenuLabel = new Label("Right Click On Me!");
final ContextMenu contextMenu = new ContextMenu(submenu);
contextMenuLabel.setContextMenu(contextMenu);
Button button = new Button("Rebuild Menu");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
contextMenu.getItems().setAll(submenu);
}
});
VBox box = new VBox(20, contextMenuLabel, button);
box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
primaryStage.setScene( new Scene( new StackPane( box ) ) );
primaryStage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
I have managed to track this issue down. It happens when a sub menu has been re-added to a ContextMenu and then shown a second time.
To reproduce:
1. Run the provided test class.
2. Right click on the label in the stage to show the context menu. Mouse over the sub menu to display it.
3. Click on the "Rebuild" button which will clear the context menu items and re add the sub menu.
4. Repeat step 2.
The second time the sub menu is show the following CSS warning will be printed to the console:
May 07, 2014 5:20:40 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.menu-item>*.label' in stylesheet jar:file:/home/csmith/dev/openjfx/build/sdk/rt/lib/ext/jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
May 07, 2014 5:20:40 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.menu-item>*.label' in stylesheet jar:file:/home/csmith/dev/openjfx/build/sdk/rt/lib/ext/jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
Ocassionally this submenu also displays with a fully transparent background which might be related to these warnings...
******************************************** Test Class ***************************************************
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class CustomMenuItemTest extends Application {
@Override public void start(final Stage primaryStage) throws Exception {
primaryStage.centerOnScreen();
primaryStage.setHeight(350);
primaryStage.setWidth(500);
final Menu submenu = new Menu("Sub Menu");
submenu.getItems().add(new MenuItem("Test 1"));
Label contextMenuLabel = new Label("Right Click On Me!");
final ContextMenu contextMenu = new ContextMenu(submenu);
contextMenuLabel.setContextMenu(contextMenu);
Button button = new Button("Rebuild Menu");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
contextMenu.getItems().setAll(submenu);
}
});
VBox box = new VBox(20, contextMenuLabel, button);
box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
primaryStage.setScene( new Scene( new StackPane( box ) ) );
primaryStage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
- relates to
-
JDK-8096217 Sub Menu Fails to show when ContextMenu is rebuilt by clearing and re-adding MenuItems
- Resolved