Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

JFrame Keep Focus

Thread view: 
Ben - 18 Mar 2006 15:42 GMT
Hi,

Is it possible to make a JFrame keep focus no matter if the user tries
to click other frames?  If so how do I do it? I was thinking of using
setFocusableWindowState on all other frames and setting them to false.
Is this the easiest way? Also is it possible to remove the x from the
top of the frame so it can only be closed using a JButton?

Thanks.

Ben.
VisionSet - 18 Mar 2006 17:23 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> Is this the easiest way? Also is it possible to remove the x from the
> top of the frame so it can only be closed using a JButton?

Not sure if this is the best way but why not add a WindowFocusListener to
the frame you want to retain focus, then when it loses focus request the
focus again?

addWindowFocusListener(new WindowAdapter() {

   public void windowLostFocus(WindowEvent evt) {
       requestFocusInWindow();
   }
});

--
Mike W
Ben - 19 Mar 2006 12:38 GMT
In the end I found that I can used setEnabled(false) on the forms to
stop users clicking on them.

Will also use
addWindowFocusListener(new WindowAdapter() {

   public void windowLostFocus(WindowEvent evt) {
       requestFocusInWindow();
   }

});

because if forms clicked on task bar they get focus even though they
can't be used.
Ben - 19 Mar 2006 12:41 GMT
Actually

addWindowFocusListener(new WindowAdapter() {

   public void windowLostFocus(WindowEvent evt) {
       requestFocusInWindow();
   }

});

didn't work when used with setEnabled(false)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.