1
这不是为我工作,在上下文菜单中没有得到显示:ContextMenu无法使用JavaFX2 TextArea?
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
/**
*
* @author Alvaro
*/
public class TextAreaContextMenu extends Application {
Group root = new Group();
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(root));
TextArea t = new TextArea();
ContextMenu m = new ContextMenu();
m.setOnShowing(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent arg0) {
System.out.println("Showing...");
}
});
MenuItem item = new MenuItem("Item");
m.getItems().add(item);
t.setContextMenu(m);
root.getChildren().add(t);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这是一个错误?或者我做错了什么? 我正在运行jdk1.7.0_02,我觉得JavaFX 2.0.2 SDK。 顺便说一句,我怎么知道,我已经安装了哪个JavaFX SDK版本?
在此先感谢您的帮助。
嘿谢尔盖,感谢您的帮助像往常一样。我正在运行2.0.3。我在2.1测试版上尝试过,它工作正常。谢谢。 – alscu 2012-03-05 15:37:13