Sono novizio su javafx. Voglio mostrare il menu popup sul clic destro del mouse. Trovo un tutorial Here e Here ma non capisco. Voglio creare menu popup che mostrano in immagine su questo link.Come creare menu popup
In questo momento sto creando un palcoscenico ma non voglio lo stage. Ho bisogno di mostrare menu popup che mostrano con il tasto destro del mouse e chiudi quando clicco ovunque.
Ecco il mio codice in cui sto usando stage ma ho bisogno di ope menu popup come sopra link.
public void MouseClickedOnTree(MouseEvent event) {
if (event.isSecondaryButtonDown()) {
System.out.println("secondary press");
final Stage optionstage = new Stage();
VBox vBox = new VBox(5);
vBox.setMinHeight(50);
vBox.setMinWidth(50);
Button btnNewTestBed = new Button("New Testbed");
btnNewTestBed.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
optionstage.close();
stage.show();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
Button btnOpenTestbed = new Button("Open Testbed");
btnOpenTestbed.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
optionstage.close();
}
});
optionstage.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent t) {
if (t.getCode() == KeyCode.ESCAPE) {
System.out.println("click on escape");
//Stage sb = (Stage) label.getScene().getWindow();//use any one object
if(optionstage.isShowing())
optionstage.close();
}
}
});
vBox.getChildren().addAll(btnNewTestBed, btnOpenTestbed);
optionstage.setScene(new Scene(vBox, 100, 100));
//stage.setScene(new Scene(new Group(new Text(50,50, "my second window"))));
optionstage.setX(event.getSceneX());
optionstage.setY(event.getScreenY());
optionstage.initStyle(StageStyle.UNDECORATED);
optionstage.show();
}
Si prega di fornire qualsiasi link o riferimento.
ma voglio mostrarlo su treeview. Voglio mostrare popup su Treeview quando faccio clic destro su treeview –
io uso questo codice ma il popup non mostra 'contextMenu.show (soariteTree, event.getScreenX(), event.getScreenY()); ' –
Scusa .. sta funzionando ora .... ho messo il codice di dichiarazione al di fuori dell'evento poi funziona; grazie ... –