-
Bug
-
Resolution: Fixed
-
P4
-
8u71
-
x86
-
other
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
Running: Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Problem is simple. I have a menu, with a few menuItems on it. When the onShowing is triggered, I check a variable and set the menuItem style based on the result. What is happening is that the style changes the 1st time, but never again. In the test change mechanism.. I can change the text, I can change the disable, no problems, so I know that the logic is making it into the routine. I tried setting the style directly at first ( the commented out lines ) but that only worked the 1st time, never again. I tried to bind a property, but that also worked the first time as well.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
menu.setOnShowing(this);
....
private SimpleStringProperty pri= new SimpleStringProperty("-fx-text-fill: orange; -fx-font-weight: bold") ;
....
....
// even tried to bind a property .. that didn’t take as well
mi.styleProperty().bind(pri);
....
// if value is default, use one style, else use another...should be simple
if (tribute != null && tribute.equals(command.argument)) {
log.warn("Tribute is equal: "+tribute.toString());
//mi.setDisable(true);
// mi.setStyle("-fx-text-fill: orange; -fx-font-weight: bold");
mi.setText("(New) Value");
pri.set("-fx-text-fill: orange; -fx-font-weight: bold");
//mi.setDisable(false);
} else {
mi.setText("(Def) Value");
pri.set("-fx-text-fill: magenta; -fx-font-weight: normal");
//mi.setStyle("-fx-text-fill: green; -fx-font-weight: normal");
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The color or font attribute should change depending on the value
ACTUAL -
The color or attribute changes ONE time, when the menu is first shown. It doesn't change after that.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No known error messages
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package menuitemproblem;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author shipmodeller
*/
public class MenuItemProblem extends Application {
Map<String, Boolean> Apple = new HashMap();
Map<String, Boolean> Orange = new HashMap();
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
VBox topContainer = new VBox(); //Creates a container to hold all Menu Objects.
MenuBar mainMenu = new MenuBar(); //Creates our main menu to hold our Sub-Menus.
// Add our test menu here
mainMenu.getMenus().add(this.getMenu());
Label btn = new Label();
btn.setText("Menu item should toggle color when selected");
topContainer.getChildren().add(mainMenu);
root.setTop(topContainer);
root.setCenter(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Menu Item Font CSS issue");
primaryStage.setScene(scene);
primaryStage.show();
}
Menu getMenu(){
Menu menu = new Menu("Tests");
menu.getItems().add( new MenuItem("Tester"));
menu.setOnShowing(new EventHandler<Event>() {
@Override
public void handle(Event event) {
EventType et = event.getEventType();
if (et.getName().equalsIgnoreCase("MENU_ON_SHOWING")) {
testAllCommonProperties((Menu) event.getSource());
return;
}
System.out.println("Hello World!");
}
});
return menu;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
boolean trigger = false;
public void testAllCommonProperties(Menu menu) {
ObservableList<MenuItem> obt = menu.getItems();
Iterator<MenuItem> menuItemIterator = obt.iterator();
while (menuItemIterator.hasNext()) {
MenuItem mi = menuItemIterator.next();
trigger = !trigger;
//Boolean tribute = Apple.get(mi.getId());
//if (tribute != null && tribute == Orange.get(mi.getId())) {
if( !trigger ){
//mi.setDisable(true);
mi.setStyle("-fx-text-fill: orange; -fx-font-weight: bold");
mi.setText("Boolean False");
} else {
mi.setStyle("-fx-text-fill: green; -fx-font-weight: normal");
mi.setText("Boolean True");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I cannot find a work around
A DESCRIPTION OF THE PROBLEM :
Running: Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Problem is simple. I have a menu, with a few menuItems on it. When the onShowing is triggered, I check a variable and set the menuItem style based on the result. What is happening is that the style changes the 1st time, but never again. In the test change mechanism.. I can change the text, I can change the disable, no problems, so I know that the logic is making it into the routine. I tried setting the style directly at first ( the commented out lines ) but that only worked the 1st time, never again. I tried to bind a property, but that also worked the first time as well.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
menu.setOnShowing(this);
....
private SimpleStringProperty pri= new SimpleStringProperty("-fx-text-fill: orange; -fx-font-weight: bold") ;
....
....
// even tried to bind a property .. that didn’t take as well
mi.styleProperty().bind(pri);
....
// if value is default, use one style, else use another...should be simple
if (tribute != null && tribute.equals(command.argument)) {
log.warn("Tribute is equal: "+tribute.toString());
//mi.setDisable(true);
// mi.setStyle("-fx-text-fill: orange; -fx-font-weight: bold");
mi.setText("(New) Value");
pri.set("-fx-text-fill: orange; -fx-font-weight: bold");
//mi.setDisable(false);
} else {
mi.setText("(Def) Value");
pri.set("-fx-text-fill: magenta; -fx-font-weight: normal");
//mi.setStyle("-fx-text-fill: green; -fx-font-weight: normal");
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The color or font attribute should change depending on the value
ACTUAL -
The color or attribute changes ONE time, when the menu is first shown. It doesn't change after that.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No known error messages
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package menuitemproblem;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author shipmodeller
*/
public class MenuItemProblem extends Application {
Map<String, Boolean> Apple = new HashMap();
Map<String, Boolean> Orange = new HashMap();
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
VBox topContainer = new VBox(); //Creates a container to hold all Menu Objects.
MenuBar mainMenu = new MenuBar(); //Creates our main menu to hold our Sub-Menus.
// Add our test menu here
mainMenu.getMenus().add(this.getMenu());
Label btn = new Label();
btn.setText("Menu item should toggle color when selected");
topContainer.getChildren().add(mainMenu);
root.setTop(topContainer);
root.setCenter(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Menu Item Font CSS issue");
primaryStage.setScene(scene);
primaryStage.show();
}
Menu getMenu(){
Menu menu = new Menu("Tests");
menu.getItems().add( new MenuItem("Tester"));
menu.setOnShowing(new EventHandler<Event>() {
@Override
public void handle(Event event) {
EventType et = event.getEventType();
if (et.getName().equalsIgnoreCase("MENU_ON_SHOWING")) {
testAllCommonProperties((Menu) event.getSource());
return;
}
System.out.println("Hello World!");
}
});
return menu;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
boolean trigger = false;
public void testAllCommonProperties(Menu menu) {
ObservableList<MenuItem> obt = menu.getItems();
Iterator<MenuItem> menuItemIterator = obt.iterator();
while (menuItemIterator.hasNext()) {
MenuItem mi = menuItemIterator.next();
trigger = !trigger;
//Boolean tribute = Apple.get(mi.getId());
//if (tribute != null && tribute == Orange.get(mi.getId())) {
if( !trigger ){
//mi.setDisable(true);
mi.setStyle("-fx-text-fill: orange; -fx-font-weight: bold");
mi.setText("Boolean False");
} else {
mi.setStyle("-fx-text-fill: green; -fx-font-weight: normal");
mi.setText("Boolean True");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I cannot find a work around