Reorder and Drag and Drop with JavaFX TabPane


Upon public request I’ve extracted my draggable TabPane from my code and made it available in a bundle who holds only controls. If you have a need for a TabPane with drag support it is as easy as grabbing “org.eclipse.fx.ui.controls_1.0.0.$TIMESTAMP.jar” from our build server (I’ll work on publishing the stuff to maven central)

Once you have the jar added to your project adding the drag support involves only:

HBox h = new HBox();
			
{
  Pane pane = DndTabPaneFactory.createDefaultDnDPane(
    FeedbackType.MARKER, this::setupTb1);
  HBox.setHgrow(pane, Priority.ALWAYS);
  h.getChildren().add(pane);
}
			
{
  Pane pane = DndTabPaneFactory.createDefaultDnDPane(
    FeedbackType.MARKER, this::setupTb2);
  HBox.setHgrow(pane, Priority.ALWAYS);
  h.getChildren().add(pane);
}

and the 2 methods setupTb1 and setupTb2 look like this:

private void setupTb1(TabPane tb) {
  {
    Tab tab = new Tab("T 1.1");
    Rectangle r = new Rectangle(100, 100);
    r.setFill(Color.GREEN);
    tab.setContent(new BorderPane(r));
    tb.getTabs().add(tab);
  }
		
  {
    Tab tab = new Tab("Tab 1.2");
    Rectangle r = new Rectangle(100, 100);
    r.setFill(Color.RED);
    tab.setContent(new BorderPane(r));
    tb.getTabs().add(tab);
  }
}

// ....

One thought on “Reorder and Drag and Drop with JavaFX TabPane

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s