我正在寻找从FlowPane中获取所选节点的方法:
public class MainApp extends Application
{
@Override
public void start(Stage primaryStage) {
// First FlowPane
FlowPane flow = new FlowPane(Orientation.VERTICAL);
flow.setColumnHalignment(HPos.LEFT);
flow.setPrefWrapLength(200);
for (int i = 0; i < 15; i++) {
flow.getChildren().add(new Label(String.valueOf(i)));
}
ContextMenu contextMenu = new ContextMenu();
flow.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
@Override
public void handle(ContextMenuEvent event) {
// Get selected image
}
});
// Second FlowPane
FlowPane secFlow = new FlowPane(Orientation.VERTICAL);
secFlow.getChildren().add(<selected image>);
}
public static void main(String[] args) {
launch(args);
}
在我的情况下,我想使用ContextMenu Node从FlowPane获取,我希望将其插入到第二个FlowPane中。有没有办法做到这一点?