Running this attached code and hitting the button makes the first Tab vanish
package controls;
import com.sun.javafx.scene.control.skin.TabPaneSkin;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Skin;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class PlaneSampleTabPane extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
HBox h = new HBox();
Scene s = new Scene(h, 400, 400);
TabPane tb = new TabPane();
{
Tab tab = new Tab("Tab 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 2");
Rectangle r = new Rectangle(100, 100);
r.setFill(Color.GREEN);
tab.setContent(new BorderPane(r));
tb.getTabs().add(tab);
}
HBox.setHgrow(tb, Priority.ALWAYS);
h.getChildren().add(tb);
Button b = new Button("Reorder");
b.setOnAction((e) -> {
Tab t = tb.getTabs().get(0);
tb.getTabs().remove(t);
tb.getTabs().add(t);
});
h.getChildren().add(b);
primaryStage.setScene(s);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package controls;
import com.sun.javafx.scene.control.skin.TabPaneSkin;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Skin;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class PlaneSampleTabPane extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
HBox h = new HBox();
Scene s = new Scene(h, 400, 400);
TabPane tb = new TabPane();
{
Tab tab = new Tab("Tab 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 2");
Rectangle r = new Rectangle(100, 100);
r.setFill(Color.GREEN);
tab.setContent(new BorderPane(r));
tb.getTabs().add(tab);
}
HBox.setHgrow(tb, Priority.ALWAYS);
h.getChildren().add(tb);
Button b = new Button("Reorder");
b.setOnAction((e) -> {
Tab t = tb.getTabs().get(0);
tb.getTabs().remove(t);
tb.getTabs().add(t);
});
h.getChildren().add(b);
primaryStage.setScene(s);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}