Configuring what element gets enter key press in JDialog?

Hi all,
In windows applications, some dialogs or windows, have a specific button that gets activated when enter is pressed. E.g. in a JDialog, the OK button would normally be activated when no button had focus. How do you set this to be? Is there some API call to do this? And is there some way to do the same with the escape key, so that cancel will always get triggered when its pressed?
I just don't want to have to manually add a key listener to each component in the dialog that listens for the escape and enter buttons to be pressed.
thanks,
J

As for the Esc key, there is nothing "out of the box" to do this. I created a JDialog sub-class to handle it, which I use in place of JDialog throughout my app. In the JDialog sub-class, over-ride the createRootPane() method as follows:
    * Overriding this method to register an action so the 'Esc' key will dismiss
    * the dialog.
    * @return a <code>JRootPane</code> with the appropiate action registered
   protected JRootPane createRootPane()
      JRootPane pane = super.createRootPane();
      pane.getInputMap( JComponent.WHEN_IN_FOCUSED_WINDOW ).
         put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "escPressed" );
      pane.getActionMap().put( "escPressed",
         new AbstractAction( "escPressed" )
            public void actionPerformed( ActionEvent actionEvent )
               onDialogClose();
      return pane;
   }then, create an abstract onDialogClose() method like the following:
    * This method gets called when the user attemps to close the JDialog via the
    * 'Esc' key.  It is up to the sub-class to implement this method and handle
    * the situation appropriately.
   protected abstract void onDialogClose();Alternatively, you could create a default implemenation of onDialogClose() instead of making it abstract; sub-classes could still over-ride it if they needed custom behavior.
HTH,
Jamie

Similar Messages

  • Capturing Enter Key Press

    Hi
      Is there a way where we can capture the Enter Key press of the Keyboard and call an event on the Enter Key Press??
    For fields such as input field there is onEnter field where an event can be called, but we have a requirement where in we need to call an event on click of enter key, irrespective of where the focus on the page is on.
    Any inpus on this will be helpful.
    Thanks & Regards,
    Gayathri Shanbhag

    Hi Gayathri,
    See if the following link helps:
    https://cw.sdn.sap.com/cw/docs/DOC-107045
    Regards,
    Himanshu

  • Capture enter key press in h:inputtext

    hi,
    i have a h:inputText component in my jsf page. i need to capture the enter key pressed for this component. how can this be done.
    thanks in advance.

    You can use Javascript for this. In the onkeypress event, check if the keycode is 13 (the enter key) and handle accordingly.
    onkeypress="if (event.keyCode == 13) alert('Enter pressed!');"

  • JSF 2.0 ajax : Submit form  on Enter key press in h:inputTextarea

    Dear All,
    I am new to JSF 2.0 . Just wanted to submit the form in ajax when a user hits the "Enter": key while typing
    in the h:inputTextarea . I would be very thankful to you guys if you help me out.
    Thanking in advance!

    I found the problem and a solution :-) The missing piece of the puzzle was the id attribute for the form tag. After some debugging of the JSF JavaScript I found the solution.
    The JavaScript function response(request, context) is invoked to handle the server response. Inside this function the doUpdate(element, context) is invoked.
    The doUpdate() function is doing the modification of the DOM. The function doUpdate() is two times invoked for a response. The first time the html elements are updated.
    The second time the view state hidden field is updated or created but only under the following condition:
    Comment in the JavaScript source code of the jsf.js
    //Now set the view state from the server into the DOM
    //but only for the form that submitted the request.If the forms of the both side haven't the same id the form can't be found on the second page.
    In the following way it is working:
    page1.xhtml
    <h:form id="myform">
            <h:commandLink value="Go to page 2" action="page2">
                <f:ajax render="@all" execute="@all"/>
            </h:commandLink>
    </h:form>
    .....page2.xhtml
    <h:form id="myform">
                <h:commandLink value="Go to page 1" action="page1">
                    <f:ajax render="@all" execute="@all"/>
                </h:commandLink>
    </h:form>So always set an explicit id for each JSF tag.

  • Enter key press instead of tab key

    I want to use enter key Instead of tab key in my page to move to next item
    Please answer in detail steps because i am new to apex and especially to Javascript

    I strongly advice against using an app like this.
    I always play by the rule not to re-invent the wheel.
    Try to convince the user from the new possibilities and the fact that tabbing is a default procedure.
    You'll see that this will be easier than actually programming the enter-key to act like the TAB key.
    I you really need to do this, then you'll need to do something like this
    http://thinksimply.com/blog/jquery-enter-tab
    good luck!
    Regards,
    Richard
    blog: http://blog.warp11.nl
    twitter: @rhjmartens
    If this question is answered, please mark the thread as closed and assign points where earned..

  • How to get the key press

    Hi,
    One more question, how do you get the keypress in the main
    movie? I've tried on onClipEvent (keyDown) key.getCode etc but that
    requires to be in a movie.

    there are a couple of ways to handle this. If you are looking
    for a sepcific Key you can set up a Listener. or more like what
    your trying here, but as in:

  • Setting component to recieve enter key presses?

    Hi all,
    if I have a dialog with a number of buttons on it, is there anyway I can set one component (an OK button) to be activated when the enter button is pressed, and another one (cancel) to be activated when the escape button is pressed?
    I know I could add actions to the action map, but isn't there usually a way to set one button to be actived on enter. It usually appears in bold, or slightly highlighted.
    thanks,
    J

    Hi all,
    if I have a dialog with a number of buttons on it, is
    there anyway I can set one component (an OK button)
    to be activated when the enter button is pressed, and
    another one (cancel) to be activated when the escape
    button is pressed?
    I know I could add actions to the action map, but
    isn't there usually a way to set one button to be
    actived on enter. It usually appears in bold, or
    slightly highlighted.
    someDialog.getRootPane().setDefaultButton(someButton);Jim S.

  • How to make the Enter key close a JDialog?

    I have a dialog box which extends JDialog. I have several buttons and other components, but I would like to make the OK button the one which reacts when the user presses Enter. Are there any specific methods to get this behaviour?

    dialog.getRootPane().setDefaultButton(okButton);

  • Repeat last command with enter key in dbx

    I am using dbx 7.7 on Solaris 10 (Sun Studio 12.1). Is it possible to configure dbx so that pressing the <enter> key will always repeat the previos command? for instance, if i do one "next" command, i want consequent <enter> key-presses to do "next", until i explicitly execute a different command.
    Thanks,
    Yael

    yaelfrommer wrote:
    Hello Jean,
    Thanks for this advice, i started working with dbxtool and it's very nice.
    2 questions:
    1. The Function keys (F7, F8, etc.) don't work, any idea what could be the problem?There is a bug in the dbx cmdio window where it ignores F-key. It doesn't even have
    a decent context menu. You should be able to get F7 etc working by moving the
    focus elsewhere, like the editor window.
    2. In the default .dbxrc file there's a line "button ignore step up" to "add `step up' button to GUI", but no button was added. Is there anything else i should do to make this work?
    These are really old. (we should remove them from the default .dbxrc!)
    The current way to add a button is via Debug->NewDbxButton
    Thanks,
    Yael

  • Use Enter key to execute report.

    I have a report that needs to be executed in background.It has a selection screen.The program should get executed when user presses 'ENTER' while he is inside the selection screen.At present,when 'ENTER' key is pressed,only validation is done.To execute we are  either pressing 'F8'  key or click execute button in screen.
    Now how to trap the 'ENTER' key press in  a report?

    Hi Jayaprakash,
    All PAI processing will depend on the Function Code that has been triggered at the selection screen.
    The ENTER key has no function code, whereas the "Execute" button has the function code 'ONLI'. SO what can be done is, when the user hits the ENTER key, we can programmatically set the function code to 'ONLI'. I shall give you a very small peice of code to illustrate my point.
    ===================================
    tables sscrfields.
    parameters p_vblen like vbak-vbeln obligatory.
    at selection-screen.
    if sscrfields-ucomm eq space.
    sscrfields-ucomm = 'ONLI'.
    endif.
    start-of-selection.
    write p_vblen.
    ===================================
    The above code will trigger the report output on hitting the ENTER key at the selection screen.
    What you only have to note here is that unlike with screen processing, in selection-screen processing, the function code will be made available in the field UCOMM of the structure SSCRFIELDS. However, you will have to declare this structure in your program ( using the TABLES statement as shown above ).
    Hope the explanation has been clear enough to drive the point home for you. Please get back to me otherwise.
    Regards,
    Anand Mandalika.

  • Enter key instead of TAB key

    Hi folks,
    I'd like to make the ENTER key behave the same way as the TAB key in
    the system I'm developing. I thought I would be able to do it by setting
    the ENTER as a function key (using Window.SetAsFunctionKey), and
    then after detecting an ENTER key press, request focus on the current
    fieldwidget's 'NextTabField'. However, this attribute defaults to NIL unless
    you override the default TAB sequence. And I don't really fancy setting
    the Next and Prev TabField for every onscreen field.
    Anyone done this before using a simpler method?
    By the way, I don't really want to get into a long thread about whether it is
    good practice to bypass Windows (TM) standards or not. We require
    fast data entry, and keyboard entry is essential for that.
    Cheers,
    Duncan Kinnear,
    McCarthy and Associates, Email: [email protected]
    PO Box 764, McLean Towers, Phone: +64 6 834 3360
    Shakespeare Road, Napier, New Zealand. Fax: +64 6 834 3369
    Providing Integrated Software to the Meat Processing Industry for over 10 years
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Duncan,
    The application we are building will replace legacy application and had similar
    requirements to accommodate the current users. We solved this problem by creating a
    special frame, appropriately named as the "Terminal Frame". It is distributed as
    part of the Scaffolds framework.
    The Terminal frame implements ENTER instead of TAB key. As you know the tabbing
    order in a terminal frame (top to bottom, left to right) is different than windows
    tabbing order (left to right, top to bottom). The Terminal frame solves the tabbing
    problem by constructing a "field traverse list" which includes all the fields in a
    window including nested views ordered according to their X,Y co-ordinates. It is a
    recursive method works on the same lines as described by Sakharov, Nickolay in
    earlier mail. The method also sets the NextTabField, PrevTabField references for
    each field in the traverse list.
    This framework is working very well for us. In a terminal frame world, you still
    have some user training issues as some of the fields (OutlineField, DropList,
    ArrayField, CheckBoxe etc.) behave differently for ENTER and TAB keys. But these
    are minimal compared to a complete change in style.
    Hope this is helpful.
    Good Luck,
    Shirish
    Duncan Kinnear wrote:
    On 22 Jun 99, at 23:47, Jeanne Hesler wrote:
    Do the math on this one. Be sure your users understand the cost and the
    lack of payback. I have no problem going against common practice when
    there is a good reason, but this reason just doesn't add up. Even if it
    did slow them down, which it won't, they would never lose enough time to be
    worth the work that it would take to implement.Jeanne,
    Thanks for your reply (even though it doesn't help me!).
    Don't get me wrong, I'm not advocating we abandon the TAB key
    functionality in favour of the ENTER key. I just want to ADD the ENTER
    key as a navigational aid for our 'legacy' users (and we have many). If it
    is done right, there should be no need to tell the user about it. Their
    transition to the new product would be virtually painless.
    Since I posted my original question I've realised that the cost of
    implementation is actually fairly low. And this is why. I have just
    discovered that the default tab order defined by Forte (left to right, top to
    bottom) is essentially useless for most of the windows we will be creating.
    Therefore, we will need to override it by explicitly setting the
    "NextTabField" and "PrevTabField" attributes of our input fields in virtually
    every window. As I am writing the framework for our new product, I will
    have to implement the facility to do this in the framework itself. And if we
    have our tab order defined, then adding the ENTER key functionality is
    minimal extra effort (see my original post). In fact, if I implement it in my
    "CoreWindow" (the root of my windows framework inheritence tree), then
    no-one will ever have to deal with it again.
    The TAB key is not even much of a windows data-entry standard. Many
    of our customers have defined secondary systems using Microsoft
    Access, and it uses the ENTER key (along with the TAB key) to move
    from field to field. Will these customers not complain that they cannot
    use the ENTER key to move between fields if we don't implement it?
    As we do not have the resources to completely rewrite our existing
    COBOL system (over 2 million lines of code) in one go. We will be rolling
    out the new system module by module. This means that a lot of our users
    will be switching between the new windows interface and the text-based
    unix telnet sessions. When I switch back and forth between windows
    editors and 'vi' on the unix host, I experience first-hand how mixed
    navigational facilities can hamper productivity!
    Anyway, I was just hoping there might be a little setting somewhere in
    Forte to switch this on, but as no-one has pointed it out, it seems unlikely.
    Thanks again for your input, lively discussion is always welcome.
    Cheers,
    Duncan Kinnear,
    McCarthy and Associates, Email: [email protected]
    PO Box 764, McLean Towers, Phone: +64 6 834 3360
    Shakespeare Road, Napier, New Zealand. Fax: +64 6 834 3369
    Providing Integrated Software to the Meat Processing Industry for over 10 years
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>--
    Shirish Kulkarni <mailto:[email protected]>
    Sage IT Partners <http://www.sageitpartners.com>
    44 Montgomery St. Suite 3200 San Francisco, CA 94104
    (925)210-6965 Office (415) 399-7001 Fax
    The Leaders in Internet Enabled Enterprise Computing
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Problem with disabling "ENTER" key in JTextArea

    Hi,
    I have the following codes to disable the 'ENTER' key in the JTextArea,
    but it does not work. Does anyone know why?
    KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    textarea.getKeymap().removeKeyStrokeBinding(enterKey);
    textarea.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    // do something
    Thanks,
    Pin

    I don't know how you mean "disable", but if you are going to ignore the Enter key, then add a KeyListener to the text area, and in the key pressed method, consume() the key event if the VK_ENTER was pressed. That's all, and you don't have to deal with that key binding thingy.
    The other two event types (typed and released) might be ignored, the enter is processed during key press (as it is now, with the default settings).
    The reason is that processing the Enter key (and other such internally understood keys) is done by the peer, but the peer won't get the key event if it's already consumed.
    FYI: Were it a JTextField, consuming the Enter key presses would mean that the field won't fire action events any more. Since text area does not fire action events, therefore it's a non issue.
    FYI2: Consuming the event only blocks the event to be sent to the peer, all the other listeners still get it.

  • Ctrl-F key presses fill up undo buffer

    I recently discovered a perplexing issue in Final Cut Pro.
    The Ctrl-Fkey transport keys apparently are considered actions
    by FCP and hence occupy the undo buffer. Using these keys
    to shuttle the timeline will effectively wipe out any important actions
    previously stored in the undo buffer and replace them with blank
    key presses.
    Probably not many people use these keys for that purpose however,
    some devices do such as the Bella Professional editor's keyboard.
    It has a jog/shuttle wheel built in that is configured to use these
    very key presses.
    Is there anyone who has noticed this behavior or has been able
    to resolve it? Incidentally, to use these keys as FCP designates, one
    must turn off Keyboard Navigation in the Keyboard & Mouse pref panel
    since they are already assigned by the OS.
    Dual processor G5   Mac OS X (10.4.8)  

    Steve, the ShuttlePro looks like a terrific
    controller.
    To be honest I don't think the design of the shuttle knob is that great, and I don't end up using it as much as I thought I would. It's nothing like the real edit controller shuttles of yore.
    By speed select keys are you referring to the J and L
    keys or the Ctrl-Fkey's?
    I meant the key combos that set a specific speed. As above, thinking I would use the shuttle more I set them to speeds I would actually use - skipping ones that weren't useful to me. It was a lot of work which I'll go undo now...
    It WOULD be great to have slow frame by frame play
    (JK and KL) on the shuttle as well but like you've
    already said, apparently it is unique to those
    particular keys.
    As long as you map to the actual J K and L keys from buttons you can press individually, it works. It doesn't work with the ShuttlePro knob simply because they only allow one button press to be programmed for each position.
    My problem was that I had mapped the ShuttlePro buttons and their functions to new places on the keyboard. The JK and KL functions seem to only work when you're mapping to those actual keys. So I have J K & L mapped to buttons on the ShuttlePro (their default, actually) and it works great.
    What really disappoints me is that FCP doesn't support a range of playback speeds that would allow something approximating shuttle behavior.
    Thanks for bringing the Undo problem to our attention!

  • Key Press Not Responding If You Go Back (re-do step)

    I have a software simulation in which one of the steps is to enter some numbers into a text field and press the Enter key. Works good on the first pass. If you then click the Back button and go back to a previous step the Enter key will no longer work. I have search the forums and some blogs without any luck.
    Example:
    http://elearning.biworldwide.com/misc/Soft_Sim/Soft_Sim.htm
    After you reach the text entry step and enter the correct numbers and press Enter, click the Back button (lower left) and back up to the Click Member step and re-preform the steps. When you reach the text entry the Enter key press will no longer work.
    Source CP4 file:
    http://elearning.biworldwide.com/misc/Soft_Sim/Soft_Sim.zip
    Thanks for any assistance,
    Kevinhttp://elearning.biworldwide.com/misc/Soft_Sim/Soft_Sim.htm

    All apps in the recently used apps bar or dock which is accessed by pressing the home button twice are not loaded and running. Some apps like games that have been updated to do so will be in an idle state, most will be quit, and some will run in the background when leaving the app. The number of apps that can run in the background are very few and far between because there is no reason or benefit for the overwhelming number of 3rd party apps to run in the background.
    http://whenwillapple.com/blog/2010/04/19/iphone-os-4-multitasking-explained-agai n/

  • Blue "Change" button does not respond to enter key (OS X)

    After entering a new Time in the "Edit Capture Time" screen you select change and the new time is applied. This could be done by selecting the "change" button with the mouse or by hitting the return key or the enter key (since "change" is the blue highlighted button). But in Lightroom 3 and now in Lightroom 4B the enter key doesn't work. Can you please fix this bug. Thanks!

    Just to be sure, I updated the program as follows. Click on the mouse to request focus and then hit enter key.
    Click on the mouse prints the String "enter key pressed". Then press the Enter key..no action activated.
    var button : SwingButton;
    Stage {
    title: "MyApp"
    visible: true
    scene: Scene {
    width: 100
    height: 100
    content: [
    button = SwingButton {
    text: "Button"
    action: function() {
    println("enter key pressed");
    button.requestFocus();
    onKeyPressed : function(event : KeyEvent):Void
    println("enter key pressed");
    }

Maybe you are looking for

  • HT3819 How do I get an audio book from iTunes on to a Walkman via Windows?

    Yes, I am a newbie to this.

  • Upload - Download of ABAP Development Objects

    Hi all, Is it possible to download my development objects( Report, Function Group, Dynpro...) of System 1  to the PC and then upload again  in System B? If yes, how is it done? Regards, Sükrü

  • External item category value

    If I change the external value of the field EPSTP concerning a language translation,in the following example (ES) from V to U, when I receive a SAP upgrade will I loose the new value - U? Is it going to be replaced by V? Int Code <b>7</b>            

  • Testing new Installation of WL Platform 8.1

    Hi, We are deploying WebLogic 8.1 Platform in our company. We just installed it and would like to make sure everything is working fine. What are the tests conducted to make sure all components of the platform (Portal, Workshop, Integrator, JRockit an

  • GR output

    All, For PO output type , we can create new one (eg ZNEU ) and assign to new document type . But for GR , if I need print out based on company code, each company is having different format , then if I am creating new output type and maintaining condi