Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with custom composite component and focus

809259Sep 29 2012 — edited Oct 5 2012
Hello, everybody!

I created a custom composite componente made up of a JFormattedTextField and a JButton inside a custom JPanel . You know that from the point of view of the user, there's only one component, a text field and a button assembled together. He's not aware of the panel underneath. But there's a little conceptual problem for me: when the text field has the focus, the method KeyborardFocusManager#getPermanentFocusOwner returns the text field, of course, but I wouldn't like it to be this way. I would like the JPanel to be returned as the focus owner. Of course I know there's a workaround for this: I have just to create my own utility method getFocusedComponent , for example, test if the focused component is a JFormattedTextField and see if its parent is the custom JPanel . But is there a simpler and elegant way?

Thank you.

Marcos
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2012
Added on Sep 29 2012
7 comments
227 views