package tests; import java.util.List; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author sjiang */ public class MyTabPane extends Application { public static boolean toAdd = false; public static void main(String[] args) throws Exception { Application.launch(args); } @Override public void start(Stage stage) throws Exception { TabPane tp1 = create("1"); tp1.setManaged(false); TabPane tp2 = create("2"); Group g = new Group(tp1); g.resize(200, 200); Scene scene = new Scene(g); stage.setScene(scene); stage.show(); tp2.resizeRelocate(0, 200, 200, 20); } public TabPane create(String id) { final TabPane tabPane = new TabPane(); Rectangle rec1 = new Rectangle(50, 50); rec1.setFill(Color.RED); Tab tab1 = new Tab(); tab1.setContent(rec1); tab1.setText("1"); Rectangle rec2 = new Rectangle(50, 50); rec2.setFill(Color.BLACK); Tab tab2 = new Tab(); tab2.setContent(rec2); tab2.setText("2"); Rectangle rec3 = new Rectangle(50, 50); rec3.setFill(Color.BLUE); Tab tab3 = new Tab(); tab3.setContent(rec3); tab3.setText("3"); tabPane.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent me) { if (me.isShiftDown()) { List tabs = tabPane.getTabs(); ppp("\n---jsl old tab list: ", tabs); Tab tab = tabs.remove(0); tabs.add(tab); ppp("---jsl new tab list: ", tabPane.getTabs()); } } }); tabPane.getTabs().addAll(tab1, tab2, tab3); tabPane.resize(200, 300); return tabPane; } private static void ppp(String msg, List list) { System.out.println(msg); for (Tab t : list) { System.out.println("\t"+t.getText()); } } }