-
Bug
-
Resolution: Fixed
-
P3
-
fx2.1
-
Mac OS X 10.6
1) Here is the NPE exception:
Glass detected outstanding Java exception at +[GlassHelper ApplicationNotifyDidBecomeActiveMethod]:src/com/sun/mat/ui/GlassHelper.m:171
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.tk.quantum.PixelUtils.imageToPixels(PixelUtils.java:43)
at com.sun.javafx.tk.quantum.GlassSystemMenu.getPixels(GlassSystemMenu.java:267)
at com.sun.javafx.tk.quantum.GlassSystemMenu.addMenuItem(GlassSystemMenu.java:197)
at com.sun.javafx.tk.quantum.GlassSystemMenu.addMenu(GlassSystemMenu.java:118)
at com.sun.javafx.tk.quantum.GlassSystemMenu.setMenus(GlassSystemMenu.java:92)
at com.sun.javafx.scene.control.skin.MenuBarSkin.setSystemMenu(MenuBarSkin.java:107)
at com.sun.javafx.scene.control.skin.MenuBarSkin.access$8(MenuBarSkin.java:100)
at com.sun.javafx.scene.control.skin.MenuBarSkin$2.invalidated(MenuBarSkin.java:117)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:359)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:197)
at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.access$1(ReadOnlyBooleanWrapper.java:196)
at javafx.beans.property.ReadOnlyBooleanWrapper.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:163)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:130)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:163)
at javafx.stage.Window.setFocused(Window.java:345)
at com.sun.javafx.stage.WindowPeerListener.changedFocused(WindowPeerListener.java:65)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:47)
at com.sun.glass.ui.Window.handleWindowEvent(Window.java:934)
at com.sun.glass.ui.Window.notifyFocus(Window.java:913)
2) Here is the code that causes it (Notice "A BAD URL" is used in one of the images):
package helloworld;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class HelloMenu extends Application {
//private static final String imageURL = "file:src/helloworld/about_16.png";
private CheckMenuItem showMessagesItem;
@Override public void start(Stage stage) {
stage.setTitle("Hello Menu");
Scene scene = new Scene(new VBox(), 400, 350);
final MenuBar menuBar = new MenuBar();
//menuBar.setUseSystemMenuBar(true);
EventHandler actionHandler = new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
if (t.getTarget() instanceof MenuItem) {
System.out.println(((MenuItem)t.getTarget()).getText() + " - action called");
}
}
};
// --- Menu 1
final Menu menu1 = makeMenu("_Debug");
// Menu menu11 = makeMenu("_New", new ImageView(new Image(getClass().getResourceAsStream("about_16.png"))));
final Menu menu11 = makeMenu("_New", new ImageView(new Image("A BAD URL")));
MenuItem menu12 = new MenuItem("_Open", new ImageView(new Image("src/helloworld/folder_16.png")));
menu12.setOnAction(actionHandler);
Menu menu13 = makeMenu("_Submenu");
showMessagesItem = new CheckMenuItem("Enable onShowing/onHiding _messages");
MenuItem menu15 = new MenuItem("E_xit");
menu15.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
System.exit(0);
}
});
menu1.getItems().addAll(menu11, menu12, menu13, showMessagesItem, new SeparatorMenuItem(), menu15);
// --- Menu 11 submenu
final MenuItem menu111 = new MenuItem("blah");
menu111.setOnAction(actionHandler);
final MenuItem menu112 = new MenuItem("foo");
menu112.setOnAction(actionHandler);
final CheckMenuItem menu113 = new CheckMenuItem("Show \"foo\" item");
menu113.setSelected(true);
menu113.selectedProperty().addListener(new InvalidationListener() {
@Override public void invalidated(Observable valueModel) {
menu112.setVisible(menu113.isSelected());
System.err.println("MenuItem \"foo\" is now " + (menu112.isVisible() ? "" : "not") + " visible.");
}
});
menu11.getItems().addAll(menu111, menu112, menu113);
// --- Menu 13 submenu
MenuItem menu131 = new MenuItem("Item _1");
menu131.setOnAction(actionHandler);
MenuItem menu132 = new MenuItem("Item _2");
menu132.setOnAction(actionHandler);
menu13.getItems().addAll(menu131, menu132);
// --- Menu 2
Menu menu2 = makeMenu("_Edit");
MenuItem menu21 = new MenuItem("_Undo");
menu21.setAccelerator(KeyCombination.keyCombination("ctrl+Z"));
menu21.setOnAction(actionHandler);
MenuItem menu22 = new MenuItem("_Redo");
menu22.setAccelerator(KeyCombination.keyCombination("ctrl+Y"));
menu22.setOnAction(actionHandler);
// menu separator
MenuItem menu23 = new MenuItem("_Disabled");
menu23.setDisable(true);
menu2.getItems().addAll(menu21, menu22, new SeparatorMenuItem(), menu23);
// --- Menu 3
Menu menu3 = makeMenu("_Radio/CheckBox");
CheckMenuItem checkMI1 = new CheckMenuItem("_1 CheckMenuItem - checked");
checkMI1.setSelected(true);
CheckMenuItem checkMI2 = new CheckMenuItem("_2 CheckMenuItem - not checked");
RadioMenuItem radioMI1 = new RadioMenuItem("_3 RadioMenuItem - selected");
radioMI1.setSelected(true);
RadioMenuItem radioMI2 = new RadioMenuItem("_4 RadioMenuItem - not selected");
ToggleGroup group = new ToggleGroup();
radioMI1.setToggleGroup(group);
radioMI2.setToggleGroup(group);
InvalidationListener selectedListener = new InvalidationListener() {
@Override public void invalidated(Observable valueModel) {
MenuItem mi = (MenuItem)((BooleanProperty)valueModel).getBean();
boolean selected = ((BooleanProperty)valueModel).get();
System.err.println(mi.getText() + " - " + selected);
}
};
checkMI1.selectedProperty().addListener(selectedListener);
checkMI2.selectedProperty().addListener(selectedListener);
radioMI1.selectedProperty().addListener(selectedListener);
radioMI2.selectedProperty().addListener(selectedListener);
menu3.getItems().addAll(checkMI1, checkMI2, radioMI1, radioMI2);
// ImageView im = new ImageView();
// im.setImage(new Image(imageURL));
// cmitem.setGraphic(im);
menuBar.getMenus().add(menu1);
menuBar.getMenus().add(menu2);
menuBar.getMenus().add(menu3);
// String os = System.getProperty("os.name");
// if (os != null && os.startsWith("Mac")) {
// Menu systemMenuBarMenu = makeMenu("MenuBar _Options");
// final CheckMenuItem useSystemMenuBarCB = new CheckMenuItem("Use _System Menu Bar");
// useSystemMenuBarCB.setSelected(true);
// menuBar.useSystemMenuBarProperty().bind(useSystemMenuBarCB.selectedProperty());
// systemMenuBarMenu.getItems().add(useSystemMenuBarCB);
// menuBar.getMenus().add(systemMenuBarMenu);
// }
((VBox)scene.getRoot()).getChildren().add(menuBar);
stage.setScene(scene);
stage.show();
}
private EventHandler showHideHandler = new EventHandler<Event>() {
public void handle(Event t) {
if (showMessagesItem.isSelected()) {
System.out.println(((Menu)t.getSource()).getText() + " " + t.getEventType());
}
}
};
private Menu makeMenu(String text) {
return makeMenu(text, null);
}
private Menu makeMenu(String text, Node graphic) {
Menu menu = new Menu(text, graphic);
menu.setOnShowing(showHideHandler);
menu.setOnShown(showHideHandler);
menu.setOnHiding(showHideHandler);
menu.setOnHidden(showHideHandler);
return menu;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// com.sun.javafx.Logging.getFocusLogger().setLevel(PlatformLogger.FINE);
Application.launch(args);
}
}
Glass detected outstanding Java exception at +[GlassHelper ApplicationNotifyDidBecomeActiveMethod]:src/com/sun/mat/ui/GlassHelper.m:171
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.tk.quantum.PixelUtils.imageToPixels(PixelUtils.java:43)
at com.sun.javafx.tk.quantum.GlassSystemMenu.getPixels(GlassSystemMenu.java:267)
at com.sun.javafx.tk.quantum.GlassSystemMenu.addMenuItem(GlassSystemMenu.java:197)
at com.sun.javafx.tk.quantum.GlassSystemMenu.addMenu(GlassSystemMenu.java:118)
at com.sun.javafx.tk.quantum.GlassSystemMenu.setMenus(GlassSystemMenu.java:92)
at com.sun.javafx.scene.control.skin.MenuBarSkin.setSystemMenu(MenuBarSkin.java:107)
at com.sun.javafx.scene.control.skin.MenuBarSkin.access$8(MenuBarSkin.java:100)
at com.sun.javafx.scene.control.skin.MenuBarSkin$2.invalidated(MenuBarSkin.java:117)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:359)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:197)
at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.access$1(ReadOnlyBooleanWrapper.java:196)
at javafx.beans.property.ReadOnlyBooleanWrapper.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:163)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:130)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:163)
at javafx.stage.Window.setFocused(Window.java:345)
at com.sun.javafx.stage.WindowPeerListener.changedFocused(WindowPeerListener.java:65)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:47)
at com.sun.glass.ui.Window.handleWindowEvent(Window.java:934)
at com.sun.glass.ui.Window.notifyFocus(Window.java:913)
2) Here is the code that causes it (Notice "A BAD URL" is used in one of the images):
package helloworld;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class HelloMenu extends Application {
//private static final String imageURL = "file:src/helloworld/about_16.png";
private CheckMenuItem showMessagesItem;
@Override public void start(Stage stage) {
stage.setTitle("Hello Menu");
Scene scene = new Scene(new VBox(), 400, 350);
final MenuBar menuBar = new MenuBar();
//menuBar.setUseSystemMenuBar(true);
EventHandler actionHandler = new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
if (t.getTarget() instanceof MenuItem) {
System.out.println(((MenuItem)t.getTarget()).getText() + " - action called");
}
}
};
// --- Menu 1
final Menu menu1 = makeMenu("_Debug");
// Menu menu11 = makeMenu("_New", new ImageView(new Image(getClass().getResourceAsStream("about_16.png"))));
final Menu menu11 = makeMenu("_New", new ImageView(new Image("A BAD URL")));
MenuItem menu12 = new MenuItem("_Open", new ImageView(new Image("src/helloworld/folder_16.png")));
menu12.setOnAction(actionHandler);
Menu menu13 = makeMenu("_Submenu");
showMessagesItem = new CheckMenuItem("Enable onShowing/onHiding _messages");
MenuItem menu15 = new MenuItem("E_xit");
menu15.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
System.exit(0);
}
});
menu1.getItems().addAll(menu11, menu12, menu13, showMessagesItem, new SeparatorMenuItem(), menu15);
// --- Menu 11 submenu
final MenuItem menu111 = new MenuItem("blah");
menu111.setOnAction(actionHandler);
final MenuItem menu112 = new MenuItem("foo");
menu112.setOnAction(actionHandler);
final CheckMenuItem menu113 = new CheckMenuItem("Show \"foo\" item");
menu113.setSelected(true);
menu113.selectedProperty().addListener(new InvalidationListener() {
@Override public void invalidated(Observable valueModel) {
menu112.setVisible(menu113.isSelected());
System.err.println("MenuItem \"foo\" is now " + (menu112.isVisible() ? "" : "not") + " visible.");
}
});
menu11.getItems().addAll(menu111, menu112, menu113);
// --- Menu 13 submenu
MenuItem menu131 = new MenuItem("Item _1");
menu131.setOnAction(actionHandler);
MenuItem menu132 = new MenuItem("Item _2");
menu132.setOnAction(actionHandler);
menu13.getItems().addAll(menu131, menu132);
// --- Menu 2
Menu menu2 = makeMenu("_Edit");
MenuItem menu21 = new MenuItem("_Undo");
menu21.setAccelerator(KeyCombination.keyCombination("ctrl+Z"));
menu21.setOnAction(actionHandler);
MenuItem menu22 = new MenuItem("_Redo");
menu22.setAccelerator(KeyCombination.keyCombination("ctrl+Y"));
menu22.setOnAction(actionHandler);
// menu separator
MenuItem menu23 = new MenuItem("_Disabled");
menu23.setDisable(true);
menu2.getItems().addAll(menu21, menu22, new SeparatorMenuItem(), menu23);
// --- Menu 3
Menu menu3 = makeMenu("_Radio/CheckBox");
CheckMenuItem checkMI1 = new CheckMenuItem("_1 CheckMenuItem - checked");
checkMI1.setSelected(true);
CheckMenuItem checkMI2 = new CheckMenuItem("_2 CheckMenuItem - not checked");
RadioMenuItem radioMI1 = new RadioMenuItem("_3 RadioMenuItem - selected");
radioMI1.setSelected(true);
RadioMenuItem radioMI2 = new RadioMenuItem("_4 RadioMenuItem - not selected");
ToggleGroup group = new ToggleGroup();
radioMI1.setToggleGroup(group);
radioMI2.setToggleGroup(group);
InvalidationListener selectedListener = new InvalidationListener() {
@Override public void invalidated(Observable valueModel) {
MenuItem mi = (MenuItem)((BooleanProperty)valueModel).getBean();
boolean selected = ((BooleanProperty)valueModel).get();
System.err.println(mi.getText() + " - " + selected);
}
};
checkMI1.selectedProperty().addListener(selectedListener);
checkMI2.selectedProperty().addListener(selectedListener);
radioMI1.selectedProperty().addListener(selectedListener);
radioMI2.selectedProperty().addListener(selectedListener);
menu3.getItems().addAll(checkMI1, checkMI2, radioMI1, radioMI2);
// ImageView im = new ImageView();
// im.setImage(new Image(imageURL));
// cmitem.setGraphic(im);
menuBar.getMenus().add(menu1);
menuBar.getMenus().add(menu2);
menuBar.getMenus().add(menu3);
// String os = System.getProperty("os.name");
// if (os != null && os.startsWith("Mac")) {
// Menu systemMenuBarMenu = makeMenu("MenuBar _Options");
// final CheckMenuItem useSystemMenuBarCB = new CheckMenuItem("Use _System Menu Bar");
// useSystemMenuBarCB.setSelected(true);
// menuBar.useSystemMenuBarProperty().bind(useSystemMenuBarCB.selectedProperty());
// systemMenuBarMenu.getItems().add(useSystemMenuBarCB);
// menuBar.getMenus().add(systemMenuBarMenu);
// }
((VBox)scene.getRoot()).getChildren().add(menuBar);
stage.setScene(scene);
stage.show();
}
private EventHandler showHideHandler = new EventHandler<Event>() {
public void handle(Event t) {
if (showMessagesItem.isSelected()) {
System.out.println(((Menu)t.getSource()).getText() + " " + t.getEventType());
}
}
};
private Menu makeMenu(String text) {
return makeMenu(text, null);
}
private Menu makeMenu(String text, Node graphic) {
Menu menu = new Menu(text, graphic);
menu.setOnShowing(showHideHandler);
menu.setOnShown(showHideHandler);
menu.setOnHiding(showHideHandler);
menu.setOnHidden(showHideHandler);
return menu;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// com.sun.javafx.Logging.getFocusLogger().setLevel(PlatformLogger.FINE);
Application.launch(args);
}
}