开发者

In which situation does a JComponent request to get focus? How to know which component is actually the focus owner?

I have a bug in my application that i'm not able to find.

I have some selectable and resizable JPanel , which display a border when selected. For some of them the border dissapear after moving them, without apparently any reason. Since now i have found no bug in my app, (no other component that the selected one is requesting or gaining focus) but i noticed that when my selected component loses the focus, the JToolbar gain it.

So my question is, in which situations (maybe involving MouseEvents), does the JToolbar component request to have focus ?

Alternatively, is there anyway to disable JToolbar for requesting focus or to know开发者_运维百科 which component is the current focus owner?


I think it's difficult to prevent focus obtaining. There are cases e.g. editable JCombobox on your toolbar when focus must be out of your panel. I would play with FocusEvent if the public Component getOppositeComponent() return one of the panel's children the border should remain.


I finally solved my problem. I noticed than setting a focused component to invisible, automatically release the focus. JToolbar wasn't directly involved in this process, but was the component directly upside in the components hierarchy so it gained the lost focus. So if I have to set a component invisible and then visible again, it must acquire again the focus explicitly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜