Problem with custom composite component and focus
809259Sep 29 2012 — edited Oct 5 2012Hello, 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