Loosing & gaining focus of a window.

In my GUI, I have created a window, that is having 2 buttons named "Enabled" & "Disabled".
MY requirement is: After execution of the window when I will click "Disable" button, the window should loose its focus and then clicking the " Enable" button the window should gain its focus.
Here I have written the code bellow for visibility of the window, but I haven't written code for the action to be performed by the 2 buttons.
If any of you have the idea about my requirement, please write me the updated code satisfying my requirement, sothat I'll proceed further.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class window extends JFrame
     public window()
          Container con=getContentPane();
          addWindowListener(new WindowAdapter(){
               public void windowClosing(WindowEvent e)
                    System.exit(0);
          JPanel p1=new JPanel();
          JPanel p2=new JPanel();
          JButton b1=new JButton("Enable");
          JButton b2=new JButton("Disable");
          p2.add(b1);
          p2.add(b2);
          con.add(p1,"Center");
          con.add(p2,"South");
          setSize(300,200);
          show();
     public static void main(String arg[])
          new window();
Regards.
          

Use a JDialog as the secondary window and make sure you specify the frame as the owner when you create the dialog.

Similar Messages

  • Save As dialog box does not gain focus (bring to foreground) with Windows 7?

    Hello,
    I've got several users with Microsoft Windows 7 (64bit) and Adobe Acrobat 9 Standard (OEM) with the same problem.  When you go to Print to your PDF Printer, the Save As... dialog box does not come to the foreground and gain focus.  Most often it just sits in the taskbar blinking to get their attention.
    However the users get frustrated and often don't realize the Save As box popped up at all.  They did not have this problem with Windows XP.
    I actually can replicate the problem on my own PC.
    Any workarounds for this behaviour?
    Thanks,
    -Tim

    This appears to be a Windows 7 focus issue.
    You can back up your registry and try the fix below, it worked for me.
    Fix number 1
    1. Open Start >> Run and type “regedit” (without quotes)
    2. Navigate to the following path:
    [HKEY_CURRENT_USER\Control Panel\Desktop]
    3. Right Click on the empty space and create a new DWORD value, or modify the existing value named ‘ForegroundLockTimeout’, set or modify the value to 0. (this value will cause the application to take the focus instantly.)
    4. That’s it Done, exit registry and restart windows for changes to come into effect.

  • Windows not gaining focus...

    Hello!
    After recent update (I can't recall having this issue before) windows that previously had focus, but lost it after I opened a new window, do not gain focus after I close the new window. This is very irritating, because now I have to click on the old window all the time, even though it is the top window, to give commands to it.
    The same thing happens also when switching spaces - if I have a window with focus in one space, quickly switch to another to check something (without clicking anywhere) and then go back to the first one, I have to click in the window otherwise I can't write or send commands to it. Even though the cursor is in the window and blinking as if it had focus (if it is an input field).
    A concrete example:
    I am writing this text in Firefox in a textbox on a webpage. I switch spaces forth and back. The cursor is still in the textbox and blinking, but whatever I press nothing happens. Firefox is still the active application (it has the menubar).
    I've tried searching, but wasn't lucky to find anything, is it just me?
    BR,
    stormmind

    It work well in my system. Either on appletview and browser.
    Firefox 3 on Debian Lenny, java 1.6.0_07-b06

  • Installing apps from dmg file package content windows doesn't gain focus

    When I download a dmg file and double click to mount, after it mounts, the window containing the package contents never gains focus and stays hidden behind the rest of the windows that are open and I have to use Expose to find it. Is this an error or setting I've missed? On my friend's iMac it works fine but not on my MacBook Pro and we both have Snow Leopard.
    Thanks

    Ok the first option didn't have any effect. When I opened the dmg from Chrome it loaded the window in the background.
    Dragging the dmg onto the DiskMounter app worked. The window opened allowing me to drag the App to the Applications folder and was in focus.
    I have a similar issue when I open an archive(zip) file from chrome/safari/firefox it shows the progress of the unarchiving bu then the finder window that would normally come to focus displaying the unarchived folder is hidden behind my other open windows.

  • Window with applet tag gains focus prior to new window browser window

    setup a :
    1. sample index.html page:
    <HTML>
    <HEAD>
    <script>
    var _load=function(){window.open('test.html');};
    window.attachEvent("onload", _load);
    </script>
    </HEAD>
    <BODY>
    <applet code=Index name=Index width=1 height=1 align=baseline>
    </BODY>
    </HTML>
    2. and child test.html window of the above (opened during onload event)
    <HTML>
    <HEAD>
    <TITLE>1</TITLE>
    <script>
    var _load=function(){window.focus();};
    window.attachEvent("onload", _load);
    </script>
    </HEAD>
    <BODY>
    TEST PAGE
    </BODY>
    </HTML>
    when a test.html page is opened focus is temporarily shifted back to the index.html page and
    only later back to the test.html page (window.focus()) call in that page sets the focus, not always
    suceeds, a further code is required to do a retry)
    when the applet is removed from the index.html page, problem goes away, it is if the applet tag
    has priority in terms of window focus
    byproduct of this is also annoying flicker, (while the focus is shifted between index.html and test.html page)
    this problem is only happening with SUN JVM (and I dont know if its a defect or by design)
    SUN JVM tested:
    Java(TM) Plug-in: Version 1.4.2_03
    Using JRE version 1.4.2_03 Java HotSpot(TM) Client VM
    suggestions, workarounds? appreciate in advance

    tested following matrix of browser/VM
    Platform Result:
    MS IE and Microsoft (R) VM for Java, 5.0 Release 5.0.0.3810 (with success, no focus problems)
    MS IE and Java(TM) Plug-in: Version 1.4.2_03 (focus problems, in the case of
    two applets one coded on the
    main page the other on the pop-
    up window)
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
    Plug-in: Version 1.4.2_03 Using JRE version 1.4.2_03 Java HotSpot(TM) Client VM
    (focus problems, in the case of one applet on
    the main page or in the case of two applets
    one coded on the main page the other on the
    pop-up window)
    Please see revised test case source code (to support above configurations, as well inclusion of the second
    applet to address discrepency in behaviour between Mozilla and IE (with SUN JVM)
    <HTML>
    <HEAD>
    <script>
    String.prototype.contains=function(s){return(this.toLowerCase().indexOf(s.toLowerCase())!=-1);};
    var u_n=navigator;
    var u_agt=u_n.userAgent.toLowerCase();
    var u_MSIE=(u_agt.contains("msie"));
    var _load=function(){window.open('test.html');};
    if (u_MSIE)
    window.attachEvent("onload", _load);
    else
    window.addEventListener("load", _load, false);
    </script>
    </HEAD>
    <BODY>
    <applet code=Index name=Index width=1 height=1 align=baseline>
    </BODY>
    </HTML>
    <HTML>
    <HEAD>
    <TITLE>1</TITLE>
    <script>
    String.prototype.contains=function(s){return(this.toLowerCase().indexOf(s.toLowerCase())!=-1);};
    var u_n=navigator;
    var u_agt=u_n.userAgent.toLowerCase();
    var u_MSIE=(u_agt.contains("msie"));
    var _load=function(){window.focus();};
    if (u_MSIE)
    window.attachEvent("onload", _load);
    else
    window.addEventListener("load", _load, false);
    </script>
    </HEAD>
    <BODY>
    TEST PAGE
    <applet code=Test name=Test width=1 height=1 align=baseline>
    </BODY>
    </HTML>
    Index.java source code:
    public class Index extends Applet {
    public synchronized void init() {
    public synchronized void start() {
    public synchronized void stop(){
    public synchronized void destroy(){
    Test.java source code:
    public class Test extends Applet {
    public synchronized void init() {
    public synchronized void start() {
    public synchronized void stop(){
    public synchronized void destroy(){

  • Excel 2010 not gaining focus correctly

    I am seeing this on my own workstation, but I'm being asked about it by more and more clients lately - Excel 2010 seems to have odd focus issues. For example:
    a) When opening an Excel spreadsheet from Windows Explorer, Excel opens, appears to have focus and does correctly open on top of other open windows, displays the file and I can edit cells, but I cannot click anything in the Ribbon bar or menus. In order
    to gain access to menu items I first have to lose focus (by clicking to another open application, the Task Bar or Desktop - anything that takes focus away from Excel) and then click back into Excel, whereupon the menu items now work correctly.
    b) If Excel is already open and I open another Excel file from Windows Explorer, the new window isn't brought forward - it remains behind the previously open spreadsheet. In addition, Excel isn't given focus at all in this situation - it is retained by Windows
    Explorer (which may or may not be open on the same screen as Excel, although it's more obvious if they overlap as Excel clearly remains behind the Explorer window). Additionally, if all existing spreadsheets are closed but Excel remains open and I open a spreadsheet
    from Explorer, the same behaviour occurs (ie Excel fails to gain focus and it is retained by Explorer).
    My personal workstation is running Windows 7 Pro x64 SP1 (this behaviour was evident before SP1's release) and Excel 2010 version 14.0.4760.1000 (32-bit). I have seen it occuring on other PCs using both 32- and 64-bit versions of Windows 7 Pro and Excel
    2010 (all 32-bit). While the workaround is relatively simple, it's still frustrating (and more than a little confusing for many non-technical people - one of my clients has been frustrated by this for weeks before I discovered she was experiencing the issue).
    I find it a little strange that I have been unable to find references to this problem anywhere (and I've been looking on-and-off for several months now). Maybe I'm just looking for the wrong things... Any help that can be provided will be greatly appreciated.
    Trevor Hardy

    I'm really not sure about the ethics of people being able to mark their own replies as accepted answers on here...
    Jennifer, thank you for attempting to assist with this problem. Unfortunately your suggestion doesn't alleviate the issue.
    As I thought I made clear in my first post, this issue is being seen when opening Excel spreadsheets directly from Explorer (or a desktop shortcut or similar, which is just an Explorer instance anyway) - it doesn't occur if you open files from within Excel.
    Therefore, opening Excel in Safe Mode has no effect - you can open one instance of Excel in safe mode, but when you open another Excel file from outside Excel, of course it opens another instance of Excel in normal mode and the same symptoms are evident.
    However, your suggestion regarding add-ins was a sensible one, so I manually removed the two Adobe Acrobat add-ins that were active on my workstation (the only add-ins installed) but unfortunately that hasn't made any difference. I should also point out
    that these add-ins aren't installed on the other PCs that are experiencing this issue, either, as they are used in wholly different environments.
    I'll be setting up Office 2010 on some new PCs in a couple of days, so I'll do some testing of those to see if I can replicate it on virgin systems.

  • Problem gaining focus

    Hi all, Im writing an applicaiton and I'm having some trouble getting the focus where I want it and was wondering if anyone could give me a suggestion.
    Here's the setup: I have a JFrame with a JToolBar on it. One of the buttons on the toolbar fires an extention of PAction that I setup. This PAction brings up a JInternalFrame with an optionpane on it that allows the user to enter/edit several pieces of info (several JTextComponents). On this InternalFrame is an InternalFrameListener, on its internalFrameActivated event I do a requestFocus() on the first JTextComponent on the InternalFrame.
    Whats currently happening is that the internalframe is activating and being selected, but the focus seems to be remaining on the toolbar's button. If I fire the same action using a method other than the toolbar (like the menu), the focus goes exactly where I want it.
    Here's what I know so far from debugging:
    1) The listener is definetly firing.
    2) The component never gains focus (in otherwords, im not loosing it after the request)
    3) There is a thread running but it's sleeping until the ok or cancel button is pressed.
    Here's what I've tried so far:
    1) Removing the thread
    2) Requesting focus on the first component: after the frame is opened, after the frame is activated, at the end of the PAction, and having the action reselect the internalframe then give the component focus
    3) I verified there are no other action listeners on the button.
    4) Stared blankly at my screen for a long time lost in thought.
    Any help will be very appreciated,
    Kris

    I experienced the same problem and the way I resolved it
    was making the toolbar buttons non-focusable.
    But this may not be good for you if you need to navigate the
    toolbar with the keyboard.

  • Dir11 is loosing keyboard focus!

    I have a kiosk application running WITHOUT a mouse. All
    inputs is from the keyboard. The app is autostarting when Windows
    starts.
    After playing a Flash animation and a mpeg2 video (Mpeg adv
    xtra) the application looses keyboard focus, wich result in Windows
    warning sound when you press a key and the key is not sent to the
    application.
    The problem is solved if you click with a mouse, but there is
    no mouse as I mentioned. The problem is NOT solved by <alt>
    <tab>-switching forth and back.
    I know this is an old MX2004 bug, and the work around then
    was to set the document type to "tool". But this is not helping in
    Dir11.
    Anyone hwo has a work around?
    Where to report bugs now a days? Does Adobe care at all?
    (It's not easy to even find the Director support pages!)

    Hi,
    maybe you can use one of the Xtras than can simulate a
    mouseclick?
    Richard
    "stageit ab" <[email protected]> wrote in
    message
    news:ganvvs$2as$[email protected]..
    >I have a kiosk application running WITHOUT a mouse. All
    inputs is
    >from the
    > keyboard. The app is autostarting when Windows starts.
    > After playing a Flash animation and a mpeg2 video (Mpeg
    adv xtra)
    > the
    > application looses keyboard focus, wich result in
    Windows warning
    > sound when
    > you press a key and the key is not sent to the
    application.
    > The problem is solved if you click with a mouse, but
    there is no
    > mouse as I
    > mentioned. The problem is NOT solved by <alt>
    <tab>-switching forth
    > and back.
    >
    > I know this is an old MX2004 bug, and the work around
    then was to
    > set the
    > document type to "tool". But this is not helping in
    Dir11.
    >
    > Anyone hwo has a work around?
    > Where to report bugs now a days? Does Adobe care at all?
    (It's not
    > easy to
    > even find the Director support pages!)
    >
    >
    >

  • Popup a JDialog without it gaining focus. Can it be done?

    Can it be done?
    I have thought about having a JDialog already on screen but positioned off screen and move it onscreen when needed but seems a ugly idea. Any one got a nicer solution?

    setFocusableWindowState(false) sort of works but the jDialog does gain focus then focus is given back to whatever window had focus before the JDialog was shown.

  • Loosing Application Focus

    My Imac keeps loosing focus of the window I'm operating out of.
    Examples:
    During a skype video call the display window will go "out of focus" and leave me with the mini viewer. I only know this to happen when an application is in use over skype.
    Typing this post application looses focus and typing does not enter the text box, I have to click back into chrome to continue typing
    when using launchpad scrolling through applications it shuts suddenly.
    I have looked at the system moniter and no processes stand out that could be causing the problem
    Running applications are Chrome, Finder and Mail
    Before this happens, there are no bouncing icons in dock and nothing is in the application menu when this happens.

    See if this helps you :
    http://maketecheasier.com/mac-keeping-your-application-window-%E2%80%98always-on -top%E2%80%99/2008/07/09

  • Adobe CC Updated disappears, if it loose the focus!

    Hi!
    I updated the Adobe CC Updater, but I've still this issue:
    If the Adobe Updater loose the focus, it disappears. Then I've to open it again via the Systray.
    That is a little bit annoying, especially if you want just to use your password manager to login again, as the updater continues to forget the login credentials.
    Could you please disable this "feature", that the Adobe CC Updater disappears, if it loose the focus?
    The only positive thing is: It really just disappears and does not close! So the entered information are still there, but the window is not available until you reopen it. But still it's a little bit annoying!
    Thanks

    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform for bugs or feature requests

  • "Move focus to next window" shortcut in full screen mode

    Does anyone know how to use the "Move focus to next window" sortcut when in "full screen" mode?
    When using a smaller screen (Macbook Air) full screen mode is a nice idea but I keep turning it off becauase the normal shortcut doesn't work.
    Any pointers in the right direction would be much appreciated.
    Cheers

    I can't duplicate your problem with my setup. Try deleting the iPhoto preference file, com.apple.iPhoto.plist, that resides in your User/Library/Preferences folder and see if that will help. Often a damaged or corrupted pref file will cause some very unusual performance issues with iPhoto.
    Also you can try rebuilding the library while selecting just the option to rebuild the database.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Applet in a browser page  doesn't gain focus with JVM 1.6.x

    Hi,
    I have a problem to move TAB in a IE browser page with applet in a tag object using JVM 1.6.x
    with JVM 1.5_10 or above this is possible. You can move focus between elements page and enter and exit to applet object.
    Executing the same applet with the same JVM, but after installation of the latest 1.6 plugin, when applet gains focus it doesn't release it.
    With JVM 1.6, applet can't gain focus and manage keyevents; all keyevents are intercepted from browser (eg: IE toolbar elements are activated) .
    I need to move focus on elements of browser page with tab, and enter and exit from applet to make my application accessible event not using mouse !!
    (you can watch a recorder right sample here: http://www.vista.it/ing_vista_0311_video_streaming_accessibile_demo.php)
    Note that FireFox doesn't work at all, even if bug seems fixed https://bugzilla.mozilla.org/show_bug.cgi?id=93149
    Please advise.

    Hi,
    We have found a wor around for this problem.
    The following option has been unchecked and the applet could be loaded.
    Go to java control panel
    Under the Advanced Tab
    Under the Security section
    Uncheck the last option "Use TLSv1.0".
    This makes the applet work.
    But could not understand as why this is creating a problem.
    We have tried to include TLSv1.0 in the cipher suite of our apache server, while keeping the above option in java plugin control panel checked, but even that did not solve the problem.
    Please help me of how should I proceed for this problem, as I am totally stuck.
    Thank you.

  • Applet looses its focus in IE

    Hello, all!
    I working with applet that will be used as a simple code editor with highlighting of different programming languages.
    This applet based on JTextPane wrapped in JScroll pane. When I test this applet with java applet viewer - all works fine, but now I embedded my applet into html page and try to test it in "live" conditions using IE browser.
    When I press TAB key inside of JTextPane the appled looses its focus instead of simply insert an indent as it should be.
    Interesting, that this problem reproduces only under IE (in Firefox it works properly).
    Maybe someone knows how to workaround this problem?
    I'll be very thankfull for answers!
    With best regards,
    Andrew.

    Thanks for all who participated in resolving of my problem. It's eventually has been resolved by myself.
    The solution was very complicated and looks like unskilful workaround, but it was one, which really helped.
    So now I just want to describe it, maybe someone else will faced the similar problem.
    First I added to main class of applet following public method (for manual handling of tab key):
    public void handleTab() throws Exception{
         textPane.grabFocus();
         Document doc = textPane.getDocument();
         doc.insertString(textPane.getCaretPosition(), "\t", null);
         textPane.setCaretPosition(textPane.getCaretPosition() + 1);
    }After that I simply can invoke this method from JScript. So my wrapping page can be like this:
    <HTML>
    <HEAD>
    <BODY>
    <APPLET CODEBASE="." ARCHIVE="editor.jar" CODE="editor.applet.EditorApplet.class" NAME="editor" WIDTH="640" HEIGHT="480" MAYSCRIPT >
    </APPLET>
    <INPUT name="stub1" type=text onfocus="editor.handleTab();" style="position:absolute; top:100; left:100;">
    <INPUT name="stub2" type=text onfocus="stub1.focus();" style="position:absolute; top:150; left:100;">
    </BODY>
    </HTML>I know, this looks little bit strange, so let me clearify some details and aspects of IE behavior.
    - When I press TAB, focus goes to "stub1" input box, which invokes 'editor.handleTab' immediately. But inspite of focus was grabbeg back by applet (invoking textPane.grabFocus()), it is ALSO REMAIS IN BROWSER in inputbox. So when I press TAB again, focus moves not to "stub1" again, but to the next flow control "stub2". So in this case "stub2" must return the focus to "stub1". It is like chain reaction ;-)
    - both input box stubs has an absolute positioning and simply hidden under the applet, so all these manipulations are invisible for end-user of applet and looks like 100%-natural behavior of any editable text area.

  • How to gain focus to a JTextField in a Jwindow

    Hi Friends
    I am trying to create a Login screen which covers the entire desktop using a Jwindow.
    I have one JTextfield and JPassword field in the Jwindow but i am not able to gain focus to those text fields and not able to type anything in those fields...
    I am using java 1.4.2
    This is my program...
    public class Login implements ActionListener
            JWindow fs;
            JTextField tx1;
            JPasswordField tx2;
             public Login ()
                 fs= new JWindow(new JFrame());
                 tx1= new JTextField(12);
                 tx2= new JPasswordField(12);
                 JButton jb = new JButton();
                 fs.getContentPane().setLayout(new FlowLayout());
                 fs.getContentPane().add(tx1);
                 fs.getContentPane().add(tx2);
                 fs.getContentPane().add(jb);
                 fs.setSize(300,300);
                 fs.setVisible(true);
                 fs.show();
                 fs.toFront();
    public void actionPerformed (ActionEvent e)
         System.out.println("User id "+tx1.getText()+" and Password is : "+tx2.getText()):
    public static void main(String[] args)
        new Login();
         Can some one help me in solving this issue with JWINDOW... Plz dont suggest JFrame , since i am not willing to use that header....
    Thanks in advance
    Ur Friend.

    Swing releated questions should be posted in the Swing forum.
    Check out this posting, found in the Swing forum:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=675445
    Plz dont suggest JFrame , since i am not willing to use that header....
    JFrame.setDefaultLookAndFeelDecorated(false);

Maybe you are looking for

  • XSLT transformation on mobile

    Hello, I am developing a mobile application where i need to do an XML to XSLT transformation on the mobile phone itself. I will store XML and XSLT file in mobile and want to see a WML or XHTML file in the browser. Is WTK supporting this? Does anybody

  • IPhone Reservation and New ATT Account

    I was waiting to see reception of iPhone 4 before picking mine up later today. I am willing to take a chance and pick it up. However, I had an iPhone 3GS which I sold but had reserved the new phone with my original account. In the meantime I had port

  • Laptop shutting down? Fan overheating?

    Hi all. I have read many topics on this forum about the fan on any laptop not working, the laptop overheating or the laptop seemingly randomly shutting down. I have had this problem for about three months. I tried propping up the laptop so the fan (s

  • Mass Assignment of sales organization to products

    Hello experts, I'd like to ask if anyone knows an easy way to maintain, mass update all products or products of a category with tha sales data????? A trans. or report or smth, to assign the sales area XXX to all the products of the category YYYY. Tha

  • Can you restrict or password protect podcasts?

    I would like to do a podcast but would like to be able to restrict or password protect it. Is this possible? if not are there any other options? Thxs.