I use the Common interface, and I have a dockable of a class that inherits DefaultMultipleCDockable. If this dockable is “stacked” in a tabbed pane with other dockables, and is visible, then calling “requestFocus” on the JComponent of this dockable does not work. It seems like the focus is set to the component for a fraction of a second, and then immediately the tab of this dockable is highlighted and the focus is lost from the component.
Any idea?
The component of the default-CDockable itself is not focusable, so focus is transfered to some other component.
If it is just about setting the focused dockable you might try the method “toFront()” which every Default-CDockable has.
I don’t know what component exactly gets the focus, however when I call “requestFocus” on my component (the JPanel that I provide to the CDockable), sometimes it gets focus, other times the title bar of the dockable (the one containing the label and the buttons for maximize/minimize etc) blinks and the focus does not go to my component. I tried “toFront()” and the problem still remains.
I found out that it was an event ordering problem. Sometimes calling ‘requestFocus’ immediately after ‘toFront’ (or even using ‘SwingUtilities.invokeLater’) is not sufficient in my case, since some actions are performed in the background in this dockable, which may shift the focus again to other components.
I ended up with a “delayed requestFocus”, using a Swing Timer. This seems to work always. I requestFocus after 500 milliseconds.
Sorry to respond so late: if DF notices a focus transfer it uses „invokeLater“ itself, because playing around with the focus directly after a transfer does not work always properly. The idea to wait a few milliseconds exactly matches this problem, because your call most likely got mixed with the delayed calls of DF.
Another solution could be to call „invokeLater“ a few times (~3) to create the delay, that could safer than waiting (you never know how fast the computer is, or how fast the user clicks around ).
But that’s also something for the todo-list, to find a better way how to transfer focus in DF.
Thanks for the reply. I think all that is needed is some way to ask DF to set the focus to the dockable that it brings to front.