How to activate a dockable programmatically?

Hi,

I create a dialog with two dockables like this


    public JComponent createContentPane() {
        CControl docking = new CControl(this);
        CGrid grid = new CGrid(docking);

        BasicDockable players = new BasicDockable(...);
        servers = new BasicDockable(...);

        grid.add(0, 0, 1, 1, servers);
        grid.add(0, 0, 1, 1, players);
        docking.getContentArea().deploy(grid);

        return docking.getContentArea();
    }

where “this” is a JDialog implementing WindowProvider.
The above code creates the dockables looking like a JTabbedPane, with “players” being the topmost dockable and none of them active.
“servers” is the first tab, “players” is the second tab.

I’d like to keep the tab order, but bringing “servers” to top and activate it.

So I added a servers.toFront() like this:


   servers.toFront();
   setVisible(true);

which means, servers.toFront() is the last statement before showing the dialog.

… but nothing changes.

How can I simulate the users mouseclick on the servers tab - that it is the top dockable painted as selected/active?

BR

Gero

“toFront” tries to focus the “servers” dockable. But because neither window nor dockable is yet visible “servers” cannot gain the focus, thus nothing happens. I’ll update the API doc to make that condition more clear. The solution in your case is to tell “grid” which dockable is at the front:

grid.add(0, 0, 1, 1, players);
grid.select( 0, 0, 1, 1, servers ); // this is the new line
docking.getContentArea().deploy(grid);```

THX for the hint!

as I found out, grid.select() does only half the job, so I added a windowlistener and added servers.toFront() in the windowOpened() event …

… with the help of both it now looks as expected :slight_smile:

Great!