Tab selection when dragging a minimized tab to a stack containing only one dockable


I’ve noticed some peculiar behavior around dragging minimized tabs to an existing stack containing only one item. If there’s only one tab, the preexisting tab retains the focus after drop. If there are more than one, the dropped tab is shown/selected/focused. I’m not sure if its the intended behavior or not. This only happens if there is a single dockable in the stack, and only if you are adding a tab to the left of the existing tab.

[li]Start the UI with some minimized dockables, and one showing normally. The showing dockable is selected.
[li]Drag one of the minimized dockables to the showing dockable, so it will be placed to the left of the showing dockable in the stack (just below the caret in the title in my example
[li]Drop the tab and it’ll be selected, then things will shuffle, selecting the original dockable and hiding the dragged dockable behind.
[li]Repeat the same drag for the other minimized dockable(s) and note that they get focus/selection on drop.

Here’s a quick example that reproduces it.

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.SingleCDockableFactory;
import bibliothek.gui.dock.common.perspective.CControlPerspective;
import bibliothek.gui.dock.common.perspective.CGridPerspective;
import bibliothek.gui.dock.common.perspective.CMinimizePerspective;
import bibliothek.gui.dock.common.perspective.CPerspective;
import bibliothek.gui.dock.common.perspective.SingleCDockablePerspective;
import bibliothek.gui.dock.common.theme.ThemeMap;
import bibliothek.util.Filter;

public class TabSelectionBug
	private static final String LITTLE_GUY_TITLE = "Drag me!";
	private static final String BIG_GUY_TITLE = "^ Drag a tab to the caret";
	CControl mainControl;

	public void show()
	    throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException

		JFrame frame = new JFrame();
		mainControl = new CControl(frame);

		TitleLabelFactory factory = new TitleLabelFactory();
		mainControl.addSingleDockableFactory(factory, factory);
		frame.setLayout(new GridLayout(1, 1));

		CControlPerspective controlPerspectives = mainControl.getPerspectives();
		CPerspective perspective = controlPerspectives.createEmptyPerspective();

		CGridPerspective center = perspective.getContentArea().getCenter();
		CMinimizePerspective west = perspective.getContentArea().getWest();

		center.gridAdd(0, 0, 600, 400, new SingleCDockablePerspective(BIG_GUY_TITLE));

		//add as many as you want here...
		west.add(new SingleCDockablePerspective(LITTLE_GUY_TITLE));
		west.add(new SingleCDockablePerspective(LITTLE_GUY_TITLE + 2));

		controlPerspectives.setPerspective("main", perspective);

		frame.setBounds(10, 10, 600, 400);

	public static void main(String[] args)
	    throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
		TabSelectionBug thing = new TabSelectionBug();;

	private class TitleLabelFactory
	    implements SingleCDockableFactory, Filter<String>
		public boolean includes(String arg0)
			return true;

		public SingleCDockable createBackup(String title)
			return new DefaultSingleCDockable(title, title, new JTextArea(new StringBuffer(title).reverse().toString()));

I'm also investigating an issue related to this in which tabs can end up selected, but not on the top of the stack, requiring the user to click away from, then back to the tab to actually focus/show it:

Like the other issue, this only ever happens if there is only one item in the stack to begin with, and you're adding the new dockable to the 0th position. Adding to the right of a single-item stack, or to the 0th position of a greater-than-one-item stack behaves like I'd expect.

Unfortunately, I'm only able to reproduce the second issue when it involves a ton of heavier UI items inside of the dockables. If I can get an example of how to reproduce it in a simple case, I'll add it here.



I’ve figured out what’s causing the focus issue. I’d been setting the focus component in my custom dockable constructor. If you replace createBackup from above with the following code, it’ll reproduce the tab hiding issue that brought all of this up in the first place.

		public SingleCDockable createBackup(String title)
			JTextArea jTextArea = new JTextArea(new StringBuffer(title).reverse().toString());
			DefaultSingleCDockable defaultSingleCDockable = new DefaultSingleCDockable(title, title, jTextArea);
			return defaultSingleCDockable;

I can work around the tab hiding by not setting the focus component, but the weird selection issue described in my first post is still there.



Sorry, I did not see this thread - completely missed it. I’ll try to reproduce this bug and fix it if possible. But this could take a while, because right now I am working on other stuff (not related to the framework) and this is not a bug that will completely stop your application from working.

Yup. Just a weird quirk. Thanks for the reply.