DockingFrames set selected tab programatically

I need to set as selected (focus on) a DefaultSingleCDockable programatically when a menu item is selected.
That tab should become active without the need for me to click on the tab with mouse but simply selecting the menu.

In Java the JTabbedPane class has the setSelectedIndex method, but in DockingFrames I can’t find anything similar.

Below an example code of what I mean.

import bibliothek.extension.gui.dock.theme.eclipse.EclipseTabDockActionLocation;
import bibliothek.extension.gui.dock.theme.eclipse.EclipseTabStateInfo;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.action.predefined.CCloseAction;
import bibliothek.gui.dock.common.theme.ThemeMap;
import bibliothek.gui.dock.common.theme.eclipse.CommonEclipseThemeConnector;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class DockingFrames
{
    public static void main(String[] args)
    {
        JFrame frame = new JFrame("Frames");
        CControl control = new CControl(frame);
        control.setTheme(ThemeMap.KEY_ECLIPSE_THEME);
        control.putProperty(EclipseTheme.THEME_CONNECTOR, new HidingEclipseThemeConnector(control));

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(control.getContentArea());

        ColorSingleCDockable red = new ColorSingleCDockable("Red", Color.RED);
        red.setCloseable(true);

        ColorSingleCDockable blue = new ColorSingleCDockable("Blue", Color.BLUE);
        blue.setCloseable(true);

        CGrid grid = new CGrid(control);
        grid.add(0, 0, 1, 1, red, blue);
        control.getContentArea().deploy(grid);

        /* creating some menus... */
        JMenuBar menubar = new JMenuBar();
        frame.setJMenuBar( menubar );
        
        JMenu showMen = new JMenu( "Show Tabs" );
        menubar.add(showMen);
        
        JMenuItem showRed = new JMenuItem("Show red");
        JMenuItem showBlue = new JMenuItem("Show blue");
        
        showRed.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                System.out.println("show red tab");
            }
        });
        
        showRed.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                System.out.println("show blue tab");
            }
        });
        
        showMen.add(showRed);
        showMen.add(showBlue);
        
        frame.setJMenuBar(menubar);
        
        frame.setSize(600, 200);
        frame.setVisible(true);
    }

    /* The EclipseThemeConnector is reponsible to fine tune the look and feel of the EclipseTheme */
    public static class HidingEclipseThemeConnector extends CommonEclipseThemeConnector
    {
        public HidingEclipseThemeConnector(CControl control)
        {
            super(control);
        }

        @Override
        protected EclipseTabDockActionLocation getLocation(CAction action, EclipseTabStateInfo tab)
        {
            if (action instanceof CCloseAction)
            {
                if (tab.isSelected())
                {
                    return EclipseTabDockActionLocation.TAB;
                }
                else
                {
                    return EclipseTabDockActionLocation.HIDDEN;
                }
            }
            return super.getLocation(action, tab);
        }
    }
}

class ColorSingleCDockable extends DefaultSingleCDockable
{
    private JPanel panel = new JPanel();

    public ColorSingleCDockable(String title, Color color)
    {
        this(title, color, 1.0f);
    }

    public ColorSingleCDockable(String title, Color color, float brightness)
    {
        super(title);
        setTitleText(title);
        setColor(color);
    }

    public void setColor(Color color)
    {
        panel = new JPanel();
        panel.setOpaque(true);
        panel.setBackground(color);
        add(panel);
    }

    public Color getColor()
    {
        return panel.getBackground();
    }
}```


Tha System.out.println("show blue tab"); should be replaced with something to set that tab as selected

I tried something in the lines of

System.out.println(„show red tab“);
DockController dockController = control.getController();
dockController.setFocusedDockable((Dockable) red, true);

However I get a

Exception in thread „AWT-EventQueue-0“ java.lang.ClassCastException: testing.ColorSingleCDockable cannot be cast to bibliothek.gui.Dockable
at testing.DockingFrames$1.actionPerformed(DockingFrames.java:64)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
[…]

Use the methode “toFront” which is part of “red” or “blue”. “toFront” makes sure that the Dockable is visible, and tries to get the focus.

Thank you, fixed it.