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);
  }
}

// ....
This entry was posted in e(fx)clipse. Bookmark the permalink.

5 Responses to Reorder and Drag and Drop with JavaFX TabPane

  1. Pingback: JavaFX links of the week, August 4 // JavaFX News, Demos and Insight // FX Experience

  2. Adrian says:

    Hey I improved your implementation by extending from TabPane so this new component can be used in fxml. If you are interested I’ll make a contribution to e(fx)clipse or just give you the source. I have never contributed anything to an eclipse project before, but I’ll try to get into it this week.

  3. Prajna says:

    Hi, I’m unable to find the jar file in the mentioned link.
    Can you please upload it again.
    Thanks in advance.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.