问题
I have (in a JavaFx app) a tabpane with different tabs. I want to implement a drag and drop functionality to drag a tab outside the stage. So that it can generate a new window (like in Google Chrome).
Thanks for the help.
回答1:
You should check the solution by Tom Schindl shown at his Blog
回答2:
Here is an aproach, its just the part of taking the content out into a new window, but its a start.
private Tab createTab(String text) {
final Tab tab = new Tab();
final Label label = new Label(text);
tab.setGraphic(label);
label.setOnDragDone(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
if (event.getAcceptedTransferMode() == null) {
final StackPane content = (StackPane) tab.getContent();
tab.setContent(null);
Stage stage = new Stage();
stage.setScene(new Scene(content));
stage.show();
tab.getTabPane().getTabs().remove(tab);
event.consume();
}
}
});
}
Basically you must create the tab with this method, and if the receiver of the event does not support draging, that is to say, if it does not do anything specific, then you create a new stackPane with the content of the tab.
*By the way is suposed the content of the pane was a StackPane.
来源:https://stackoverflow.com/questions/15313796/javafx-drag-and-drop-tabpane