• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How Do You Select a JFrame to Be the Front Window (that works for both Mac and Windows)?

 
Ranch Hand
Posts: 693
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Swing Application, using Java 5.0. For JFrame objects, I use the method called: requestFocus() on the JFrames and this causes the JFrame to become the front window, but this only works on Windows.

When I tested my app on a Mac, the request() focus method did nothing.

Does anybody have an idea of how to make a JFrame the front window in a platform-independent way?

Thanks for reading my question.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I've been trying to solve the same problem today (on Linux) and after some time of research I believe that there is no platform-independent, fully reliable way. There is another method, toFront(), but it does not work as expected. The problem is in what the JavaDocs say:

toFront()

Places this Window at the top of the stacking order and shows it in front of any other Windows in this VM. No action will take place if this Window is not visible. Some platforms do not allow Windows which own other Windows to appear on top of those owned Windows. Some platforms may not permit this VM to place its Windows above windows of native applications, or Windows of other VMs. This permission may depend on whether a Window in this VM is already focused. Every attempt will be made to move this Window as high as possible in the stacking order; however, developers should not assume that this method will move this Window above all other windows in every situation.



In my case, the frame (or rather the JDialog) was brought to front only when another frame of the same VM was focused earlier. I tried both requestFocus() and requestFocusInWindow() but with no success. As I read the behaviour is different for different versions of Windows, too (Vista behaves differently than XP and that differently than 98)... If you ever solve this, please let know in this thread.
 
Kaydell Leavitt
Ranch Hand
Posts: 693
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.

The method called: toFront() is working for me for both Vista and Mac OS 10.4. What I'm doing is implementing a Window menu like is customary on the Macintosh platform. The Window menu lists each window that you can select and when you select a menu-item, the corresponding window becomes the front window.

toFront() may not always work in every case, but it seems to be doing what I need it to do. I'll have to test is in XP and in Mac OS 10.5

 
Kaydell Leavitt
Ranch Hand
Posts: 693
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Well, maybe it's not working on the Mac yet. I'll focus on Windows Vista & XP for now.
 
ice is for people that are not already cool. Chill with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!