• Post Reply Bookmark Topic Watch Topic
  • New Topic

Giving focus(visibility) to "obsured" window/component...  RSS feed

 
Carvel Baus
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JScrollPane that at one point in the program can exist inside a JTabbedPane and at other times, exist inside of a JDialog - it gets moved based on user action. I don't know where it is at any given time, I can just get a handle to it (the it being a JScrollPane)

I want to be able to bring whatever the JScrollPane is in, to the front (gain focus??) so the user sees it when some other event occurs. So if it is in a JDialog, I want the dialog to come in front of everything (using modal dialog not an option.) If it is in the JTabbedPane, I want that tab to become selected.

1) How do I tell what the component is currently in (JTabbedPane or JDialog) programmatically and get a proper reference so that I can tell it to gain the focus?

2) What is the best way to "bring it to the front/ gain focus? I know I can use setSelectedCompenent from JTabbedPane and I am not sure on JDialog.

Thanks.
 
Suraj Chandran
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Window w = SwingUtilities.getWindowAncestor(scrollPane);
w.requestFocus();

Not guaranteed in solaris
 
Suraj Chandran
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! I realize that the above answers onlly point 2.
For point 1, maybe you could user scrollpane.getParetn isntanceof JTabbedPane kind of stuff....
I doubt though whether this anwers your question
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!