import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main implements Runnable { JTabbedPane tabbedPane = new JTabbedPane(); public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Main()); } @Override public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(800, 600)); final JButton button = new JButton("click me"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setEnabled(false); for (int i = 0; i < 500; i++) { moveTabTo(0, 1); } } }); tabbedPane.addTab("_TAB_1", new Tab(Color.ROSYBROWN)); tabbedPane.addTab("_TAB_2", new Tab(Color.LIGHTCORAL)); JPanel panel = new JPanel(new BorderLayout()); panel.add(tabbedPane, BorderLayout.CENTER); panel.add(button, BorderLayout.NORTH); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } public void moveTabTo(int fromIndex, int toIndex) { Component component = tabbedPane.getComponentAt(fromIndex); String label = tabbedPane.getTitleAt(fromIndex); String tooltip = tabbedPane.getToolTipTextAt(fromIndex); tabbedPane.remove(fromIndex); tabbedPane.insertTab(label, null, component, tooltip, toIndex); } class Tab extends JFXPanel { Tab(final Color color) { Platform.runLater(new Runnable() { @Override public void run() { setScene(new Scene(new Group(), color)); } }); } } }