• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set focus on one of the two JInternalFrame

 
Yingie Pitts
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JInternalFrames A and B that are added to a JFrame. A opens the other JInternalFrame C. After C is closed, the focus always returns to B not A. Do any of you know why?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is controlled in the DesktopManager... I think the behavior of DefaultDesktopManager is just to set the focus on the first frame it gets from getComponents(). So basically the frame that has been added to the desktop the longest. Unfortunately, the method they call to do this is not part of the API, so you'll have to implement your own DesktopManager to do this in the closeFrame() method.
 
Romnick Malabiga
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using these methods...
.moveToFront();
.setSelected(true);

but you need to enclose the .setSelected method in a try catch block..

here's an example.. I'm using netbeans..



Hope it helps.. This is my first time to post here in coderanch..
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Romnick Malabiga wrote:try using these methods...

It's not likely that Yingie Pitts is still looking for a solution 9 years after asking the question.

Romnick Malabiga wrote:This is my first time to post here in coderanch..

Welcome to the Ranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic