Thursday, August 8, 2013

How to get focus on a component in a class that extends JPanel?

How to get focus on a component in a class that extends JPanel?

I have a class named SongBox that extends JPanel. Inside it I have a field
called songTitleBox. This can be focused by other components in class but
not from outside. Do you have any ideea and solutions? Thank you in
advance.
songTitleBox.requestFocus(); // this works when called from another
component in class.
If I have the following method:
public void focusOnSongTextBox() {
songTitleBox.requestFocus();
}
and I try to call it from outside the component like this
songBox.focusOnSongTextBox()
is not focused

No comments:

Post a Comment