Temporary focus for a popup?

Hi, this is NOT URGENT, just a little brain teaser I have come upon myself.
I have a calendar-like component that I want to display on a popup. The user may open it (with a button) and choose something with the mouse (which hides the popup and fires an event). No problem there.
In the interest of not requiring mouse use (a big deal with me), I put in the handling value various keystrokes (<arrows/pageup/pagedn> move around; <enter> or <space> make selection; <escape> closes without selection, etc.). But I cannot figure out how to get the keystrokes delivered to my component because I can't seem to understand the temporary focus situation with popups.
I have tried writing my own JPopupMenu and Popup implementations, tried to manually move focus around, tried tweaking around with the MenuSelectionManager to see if it is eating my keystrokes, but I can't get it to work, and I know that there must be something much simpler that I am not seeing.
BTW, I am trying to not have to muck with the Input/Action Maps of the window (or of any ancestor component higher than the popup itself), though I have considered that I could change them when popup opens and restore them when popup closes. Like I said, there must be something much simpler, right?
I wrote a small sample case, which I will include in case anyone cares to give this a look.
SimplePanel just uses the arrow keys to change a Label among {N,E,S,W} values. It has a main that sticks it in a frame. The arrow key cause the label to change.
SimplePopup provides a button that opens a JPopupMenu containing a SimplePanel. (To keep it super simple, I haven't even included a way to close the popup.) User can open the popup by hitting <space> on the focused button, but cannot manipulate the SimplePanel using the arrow keys.
(I will post the code in separate messages)
Thanks,
/Mel

I have a solution -- add a KeyEventPostProcessor that redispatches the KeyEvents to the component on the popup. For the example, I just implemented KeyEventPostProcessor in this class. Hurray for 1.4!!!
My question from before still stands though: isn't there a simpler way to do this!??! Furthermore, why shouldn't this be the default behavior to begin with? (i.e. when a popup is opened on a window the popup becomes a temporarily focus root; when the popup is closed the (permanent) focus reverts to whoever had it before...)
/Mel
class SimplePopup extends JPopupMenu implements KeyEventPostProcessor
   SimplePanel content = null;
   SimplePopup(SimplePanel content)
      this.content = content;
      this.add(content);
   public boolean postProcessKeyEvent(KeyEvent e)
      if (this.isVisible())
         KeyboardFocusManager.getCurrentKeyboardFocusManager().redispatchEvent(this.content, e);
      return false;
   public void setVisible(boolean b)
      super.setVisible(b);
      if (b)
         KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(this);
      else
         KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventPostProcessor(this);
   public static void main(String[] args)
      JFrame frame = new JFrame();
      JPanel extraroom = new JPanel();
      extraroom.setBorder(new EmptyBorder(50,50,50,50));
      final JButton button = new JButton("show it");
      final SimplePanel spanel = new SimplePanel();
      final SimplePopup popupmenu = new SimplePopup(spanel);
      button.addActionListener(new ActionListener()
                                      public void actionPerformed(ActionEvent e)
                                         Point point = new Point(2, 2 + button.getBounds().height);
                                         Component window = SwingUtilities.getWindowAncestor(button);
                                         point = SwingUtilities.convertPoint(button,point,window);
                                         popupmenu.setLocation(point);
                                         popupmenu.setVisible(true);
      extraroom.add(button);
      frame.getContentPane().add(extraroom);
      frame.pack();
      frame.show();
} // end class SimplePopup

Similar Messages

  • Temporary focus changes

    Hi,
    I am trying to have a clean and robust solution for focus handling and validation on components. Is there any reference material available on this? Then the concept of temporary focus changes. Seems to me like an interesting concept to use. But then I don't know how really? In jdk1.4.2 for instance following method in JComponent is implemented like this:
        public boolean requestFocus(boolean temporary) {
         return (runInputVerifier())
             ? super.requestFocus(temporary)
             : false;
        }And it indicates that it is only there for internal usage by ui's. I would guess that the inputVerifier should not be called in case temporary is true? Or is this last assumption completely wrong?
    Many thanks,
    Marcel

    Hi,
    I am trying to have a clean and robust solution for focus handling and validation on components. Is there any reference material available on this? Then the concept of temporary focus changes. Seems to me like an interesting concept to use. But then I don't know how really? In jdk1.4.2 for instance following method in JComponent is implemented like this:
        public boolean requestFocus(boolean temporary) {
         return (runInputVerifier())
             ? super.requestFocus(temporary)
             : false;
        }And it indicates that it is only there for internal usage by ui's. I would guess that the inputVerifier should not be called in case temporary is true? Or is this last assumption completely wrong?
    Many thanks,
    Marcel

  • I need the code for creating popup windows and code for open and close

    I can write the code for creating popup window , i am getting problem while trying to open and closing that popup windows.
    Can anybody help me in that pls ?
    Regards
    Sreeni.

    Hi
    For pop up window
    IWDWindowInfo windowInfo = (IWDWindowInfo)wdComponentAPI.getComponentInfo().findInWindows("PopWin");
    IWDWindow window = wdComponentAPI.getWindowManager().createModalWindow(windowInfo);
    window.setWindowPosition (300, 150);
    window.show();
    wdContext.currentYourNodeElement().setPopupAttribute(window);
    For closing window code
    IWDWindow window = wdContext.currentYourNodeElement().getPopupAttribute();
    window.hide();
    window.destroyInstance();
    For more infornation refer this link
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/20d2def3-f0ec-2a10-6b80-877a71eccb68&overridelayout=true
    This link is very useful for you.
    Regards
    Ruturaj
    Edited by: Ruturaj Inamdar on Aug 13, 2009 9:10 AM

  • Problem with requesting focus for a list

    Hi there !
    What would be the right way to request focus for a list component ?
    I can use select() method to select some item from a list, but the list itself still hasn't got a focus until I click it.
    What I'd like to do is to be able to highlight some item from the list by using up and down arrow keys only, without clicking the list first =)

    The list is visible, but still this doesn't work.
    I think that the reason for this may be that I'm running this app on Nokia 9210 Communicator emulator. The emulator itself has had some not-so-minor problems...

  • App similar to stay focused for MacBook Air

    Is there an app similar to stay focused for MacBook Air?

    There is a way to see (in small window) short bits and parts of video movies, where they exist, in the iTunes application from the store page in there. My older Mac with earlier version of iTunes lets me browse Music, Movies, TV stores, from the sections on the iTunes application; years ago there was more direct content. They used to have a site page for some of those clips... I haven't looked lately.
    A screenshot of a video clip ^ from the iTunes Movie store, via iTunes in my Mac.
    If you browse the items for sale/rent, a few have a tiny triangle on them and this opens the little window where a preview runs. A few actual movies will have an option to see a preview or trailer-like video in a similar small window that opens up over the store screen.
    The older iTunes application in earlier Mac systems had various other features. In order to view movie trailer kinds of content streamed from the internet, you may have to look into a third party application or a web page.
    There may be a list of applications included with certain models of Mac portables
    and if you can find that name, that may be a talking point. The Store has lists of
    what software may be included in the most recent Macs in each products info.
    {There was no mention prior to your reply...
    that you did not want to make movies, btw.}
    Good luck & happy computing!
    edited.

  • Webdynpro for java 怎么实现弹出一个popup window时,使原来的窗口变的不太明显?

    webdynpro for java 怎么实现弹出一个popup window时,使原来的窗口变的不明显,比如变模糊,或者消失都行。不知道怎么实现?

    创建一个modalWindow实例就可以了,如下:
    IWDWindowInfo windowInfo =(IWDWindowInfo)wdComponentAPI.getComponentInfo().findInWindows("HelloWindow");
    IWDWindow window = wdComponentAPI.getWindowManager().createModalWindow(windowInfo);
    window.setTitle("hello");
      window.show();

  • Error: You have reached the limit of active temporary sites for this account.

    When publishing a new site from Muse I got the following message:
    Error:
    Could not create Adobe Business Catalyst temporary site. You have reached the limit of active temporary sites for this account.
    I have only 17 active sites, 5 of them are launched live. All the other 83 of 100 websites limit I have already deleted in Business Catalyst and their status is shown as inactive, there is no way for me to get back to managing these 83 thus it kind of suggests that they are deleted. I need to create new sites under new names quite often to demonstrate work in progress or various options of design for the same website and I don't have any intention to use any of the 83 sites anymore. With the current error I can't work and I can't find a way to completely remove all 83 inactive sites inside Business Catalyst or Creative Cloud (I tried and searched and still nothing). So it's a huge problem for me.
    Now, how can I solve this issue?

    Hello,
    Can you open up a support ticket so that a support engineer can look at this problem? Based on this short description you should not have any problems creating new temporary sites (not live sites).
    Thank you,
    Cristinel

  • I Need Help for the popup message every time I go to safari: "Warning! Old version of Adobe Flash Player detected. Please download new version."???

    I Need Help for the popup message every time I go to safari: "Warning! Old version of Adobe Flash Player detected. Please download new version."???

    If you are talking about Safari on the iPad, there is no version of Adobe Flash for iOS and there never has been. Clear Safari, close the app and reset the iPad.
    Go to Settings>Safari>Clear History and Website Data
    In order to close apps, you have to drag the app up from the multitasking display. Double tap the home button and you will see apps lined up going left to right across the screen. Swipe to get to the app that you want to close and then swipe "up" on the app preview thumbnail to close it.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.
    If you are talking about Safari on your Mac, you are in the wrong forum. But I would still clear the cache, quit Safari and restart the Mac.

  • Datagrid focus for cell

    Hi,
    how to set focus for perticuler cell or row in datagide
    using flex 3 .Flex 2 Beta 1:
    var __focusedCell:Object = new Object();
    __focusedCell.itemIndex = 1;
    __focusedCell.columnIndex = 2;
    dg.setFocusedCell(__focusedCell,true);
    Flex 2 Beta 2:
    var __focusedCell:Object = new Object();
    __focusedCell.rowIndex = 1;
    __focusedCell.columnIndex = 2;
    dg.setEditedItemPosition(__focusedCell);
    but this functions
    (dg.setFocusedCell,dg.setEditedItemPosition) are not working in
    flex 3.0. please let me know if any body known this one

    Perhaps you could try:
    myGrid.selectedItem = -1;

  • Tcode to find the availability of temporary positions for specific org unit

    Hi all,
    What is the tcode to find the availability of temporary positions for specific org. unit??
    Thanks
    Jerry

    PPIS
    this tcode select the orgunit and positions once

  • DEFAULT TABLESPACE and TEMPORARY TABLESPACE for eBusiness Suite database

    Hi:
    What is the
    DEFAULT TABLESPACE and TEMPORARY TABLESPACE
    for eBusiness Suite database.
    I want to create a new schema on the eBusiness Suite database.
    Please help

    DEFAULT TABLESPACE and TEMPORARY TABLESPACE
    for eBusiness Suite database.
    I want to create a new schema on the eBusiness Suite database.Create a new tablespace and temporary tablespace for your custom schema (you may use the existing temporary tablespace).
    Integrating Custom Applications with Oracle Applications Release 11i [ID 176852.1]
    Step By Step Guide to Creating a Custom Application in Applications 11i [ID 216589.1]
    Thanks,
    Hussein

  • [svn:fx-trunk] 10526: Temporary workaround for A+ bug SDK-23387.

    Revision: 10526
    Author:   [email protected]
    Date:     2009-09-22 21:48:33 -0700 (Tue, 22 Sep 2009)
    Log Message:
    Temporary workaround for A+ bug SDK-23387.
    The LinkNormalFormat, LinkHoverFormat, and LinkActiveFormat classes have been removed from FXG, and the FXG compiler was autogenerating static vars of these types (for linkage reasons?) that no longer compiled. I've commented out the offending lines in FXGCompiler.java, but we need a correct fix to cope with the fact that the way hyperlinks are formatted in FXG has changed.
    Instead of formatting hyperlinks by writing
    tag) but at least it can once again compile FXG as long as it doesn't involve styled hyperlinks.
    QE notes: None
    Doc notes: None
    Bugs: SDK-23387
    Reviewer: Carol
    Tests run: ant checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23387
        http://bugs.adobe.com/jira/browse/SDK-23387
    Modified Paths:
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/fxg/FXGCompiler.java

    error dateField not selecion date 27/11/2002 ?
    This is bug flex 3 ?
    thanks

  • Using JS alert for error popup!

    Hi All,
    How to use the JS alert for error popup?
    Actualy when i tried using it , popup comes but the main calling page goes blank until OK is clicked,  whereas in normal applications or standard BSP it works normally , ie we can see the calling page in background.
    Thanks,
    Anubhav.
    Edited by: Anubhav Jain on Jun 6, 2008 10:33 AM

    Hi Anubhav
    When you execute an alert, execution flow is stopped until you click OK.
    I understand you want to popup an alert when you load a page with JS.
    Maybe you can invoke the alert when page is completelly loaded with an onload event.
    For example:
    <body on load = "function of alert">
    This way you can be sure the page is not blank when alert is displayed.
    Regards.

  • Request focus for message area

    Dear All,
    As my screen is long hence if an error comes we will require to scroll down so I have added a message area UI element and in do modify method of the view i have request focus to my message area but it is not working.  Below is the code which I have written:
    try{
              IWDMessageArea msgarea=(MessageArea)view.getElement("MessageArea");
            msgarea.requestFocus();
            catch(Exception e)
    Is there any other property or changes need to be made.
    Thankyou.
    Regards,
    Santosh

    Hi,
    In would say, create an input field at the top left corner of the screen. Set its width to zero and bind it to a context attribute say Va_ShowMesg of type string. Now insert a MessageArea UI element just below the inputfield to display all the erro message at the top left.
    Now if you request focus for the input field using the following code, the focus will automatically come to the Message Area as well.
    wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(),wdContext.getNodeInfo().getAttribute(
              wdContext.currentContextElement().VA__SHOW_MESG));
    You can call this code whenever you need to display message to user in the message area and shift focus of the screen to the message displayed.
    Regards,
    Tushar Sinha

  • Order of focus for swing components

    Hi All,
    I am in search of the way to definine the order of focus for swing components.
    I have a JPanel to which I can add multiple JButtons and JLabels. My problem is that when ever JButton comes, it should get the focus even though JLabel exists.
    If I drag the JButton on to JLabel then also it should be placed on top of the JLabel.
    Can any body help me to solve this problem.
    Thanks in advance,
    Regards,
    Roja.

    Hi,
    I am giving my sample code here.
              if (textButton != null) {
                   setUserTextPresentFlag(true);
                   textButton.setFocusPainted(false);
                   textButton.setContentAreaFilled(false);
                   textButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
                   textButton.setBounds(
                        editPosX,
                        editPosX,
                        textButton.getWidth(),
                        textButton.getHeight());
                        textButton.setRequestFocusEnabled(true);
    //                    textButton.grabFocus();
                        textButton.requestFocus();
    System.out.println("requestFocus isDisplayable::"+userTextImageButton.isDisplayable()+" isEnabled "+userTextImageButton.isEnabled()+" isFocusPainted "+userTextImageButton.isFocusPainted()+" isVisible "+userTextImageButton.isVisible()+" userTextImageButton.hasFocus() "+userTextImageButton.hasFocus());
    I am getting the following values for the system.out.println values.
    isDisplayable::false isEnabled true isFocusPainted false isVisible true userTextImageButton.hasFocus() false
    I didn't find a method to set displayable to true.
    could u find where the problem is?
    Thanks in advance,
    roja.

Maybe you are looking for