How prevention JButton to actions generated when the user press down

How prevention JButton to actions generated when the user hold down the key or the short cut
The code below to show the question when the user keep pressing Alt O
We want to stop the JButton to generate multi shares just a share only
A code example shows the behavior that needs to be prevented. Keep pressing "Alt + O" and you will see that the standard ouptput will print the timestamp
Note Please, I'm NOT interested in the mouse press which is a solution by adding a threshold (setMultiClickThreshhold (long line) on the JButton as an attribute.

 
public class TestPanel extends JPanel
{

   private JButton btn;

   public TestPanel()
   {
      btn = new JButton("Open");
      this.add(btn);
      registerCommand(new MyAction(), InputEvent.ALT_MASK,
            KeyEvent.VK_O, btn, btn.getText(), 0);
   }

   public static void registerCommand(AbstractAction action,
         int mask,
         int shortCommand,
         JComponent component,
         String actionName,
         int mnemonicIndex)
   {
      InputMap inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
      KeyStroke knappKombination = KeyStroke.getKeyStroke(shortCommand, mask);

      if ((component instanceof AbstractButton)
            && mnemonicIndex >= 0
            && mnemonicIndex < actionName.length()
            && (shortCommand >= KeyEvent.VK_A && shortCommand <= KeyEvent.VK_Z))
      {
         ((AbstractButton) component).setDisplayedMnemonicIndex(mnemonicIndex);
      }

      if (inputMap != null)
      {
         ActionMap actionMap = component.getActionMap();
         inputMap.put(knappKombination, actionName);
         if (actionMap != null)
         {
            actionMap.put(actionName, action);
         }
      }
   }

   public static class MyAction extends AbstractAction
   {

      /**
       * 
       */
      private static final long serialVersionUID = 1L;

      @Override
      public void actionPerformed(ActionEvent e)
      {
         System.out.println(System.currentTimeMillis());

      }

   }

   public static void main(String... args)
   {
      SwingUtilities.invokeLater(new Runnable()
      {
         public void run()
         {
            JFrame frame = new JFrame("Testing");
            JPanel panel = new TestPanel();
            frame.getContentPane().add(panel);
            frame.setPreferredSize(new Dimension(500, 500));
            frame.setMinimumSize(new Dimension(500, 500));
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
         }
      });
   }

}
Published by: user12130673 on 13-feb-2013 03:01

Use getKeyStroke (int keyCode, int modifiers, boolean onKeyRelease) hit with onKeyRelease = true instead?

Tags: Java

Similar Questions

  • How can I set up a structure of the event that sends text when the user presses the button "Return"?

    I'm new to programming of the Structure of the event.  I am trying a program which causes the content of a control to the string to be processed when the user presses the button back in after typing in the control of the chain.  I think (I hope!) that it is simple, I just can't understand how do.

    Basically, I would take the attached VI and change so that the user can send the value of control 'String In' to the indicator "String Out" either by pressing the 'Return' key or press the button 'send string. '

    Any help would be greatly appreciated.

    This example has nothing to do with the RETURN key specifically.  It fires all simply whenever the value of the control is changed.  If you click outside the text box or on another still controls the value changes and still the event is raised.  This is often the desired so if it works in your application, you good to go.

    You CAN ONLY answer a particular key if you wish.  Set your event to meet 'This VI' > key down.  Then, read the proposal Vcle on the left side of the structure of the event and compare it to the RETURN (for example).  The Boolean result of the comparison gets connected to a structure to deal with your code to run inside.  You can also wire Vcle directly to a case structure and execute different code based on which key was pressed last.

  • Background image disappears when the user scroll down

    Hello

    Here is a class that paints a picture as desktop wallpaper. My problem is that if a vertical scrolling is on the screen, when scrolling down the background image does not scroll also. Is it possible to repeat the background so that it is always on the screen when the user scrolls down.

    Thank you.

    SerializableAttribute public class BaseVerticalFieldManager extends VerticalFieldManager {}
        
        
    public BaseVerticalFieldManager (long style) {}
    Super (style);
    }

    Public Sub paintBackground (Graphics graphics)
    {
    graphics.drawBitmap (0, 0, Display.getWidth (), Display.getHeight (), Constants.BACKGROUND_IMAGE, 0, 0);

    }
        
    }

    adrianeireyahoo wrote:

    Public Sub paintBackground (Graphics graphics)
    {
    graphics.drawBitmap (0, 0, Display.getWidth (), Display.getHeight (), Constants.BACKGROUND_IMAGE, 0, 0);

    }

    The values highlighted are wrong - you need to keep track of the Manager scroll position. In addition, using Display.getWidth () and Display.getHeight () isn't exactly smart - use getWidth() / getHeight() Manager itself.

    In short, the correct code would be:

        public void paintBackground( Graphics graphics)
        {
            graphics.drawBitmap(getHorizontalScroll(), getVerticalScroll(), getWidth(), getHeight(), Constants.BACKGROUND_IMAGE, 0, 0);
        }
    
  • stay on the current page. When the user presses ESCAP.

    int

    if (type1 is Dialog.OK)

    {

    intask (Dialog.D_YES_NO, "Please confirm");

        if (type is Dialog.YES)

    {

    perform your task if yes

    ClearAll();

    Login_Screen.disconnect ();

    UiApplication.getUiApplication () .pushScreen (new L_Screen());

    }

    }

    if (type1 is Dialog.CANCEL)

    {

    What should the code because I want to stay on the page current user //press whe cancel but

    }

    Type1 = Dialog.ask (Dialog.D_OK_CANCEL, "Do you want to disconnect now?");

    Hello friends,

    I do the page to disconnect. I want to give confurmation beform logout. Everthing is working. but

    Aler dialogue ask first you want to disconnect or not?

    If he says cancle I want to stay on the current page. but still he go on the back. When your press esce I check everything.

    Please tell me what is the code to stay on the current page when the user press cancle alser dialogue?

    That's what I understood.

    I don't think you understood what I was saying. so here's an example of code:

        protected boolean keyChar(char character, int status, int time) {
            switch (character) {
                case Characters.ESCAPE:
                    confirmClose();
                    return true;
                default:
                    return super.keyChar(character, status, time);
            }
    
        }
    
        private void confirmClose() {
            int resp = Dialog.ask(Dialog.D_YES_NO,"Do you really want to Quit",Dialog.NO);
            if ( resp == Dialog.YES ) {
                resp = Dialog.ask(Dialog.D_YES_NO,"Do you really, really want to Quit",Dialog.YES);
                if ( resp == Dialog.YES ) {
                    // Close the screen as you currently do it
                }
            }
        }
    

    If you don't mind asking me, please use English. for example, the letter "y" is, is not the question why.  I recommend this spell check you your messages also, don't forget that a lot of people who use these forums are not native English speakers, so we use English must be as clear as possible.

  • Open a new window when the user presses the button

    Hello

    I have a button (BUTTON HTML) that opens a URL... but it opens URL in the same window...

    is there a way to open a new window (popup) when the user presses the button...

    Thanks in advance

    Hello

    Just change the button to the target URL.

    Specify the URL like: javascript:popupURL('__');

    popupURL is a function of popup. You can use the pop-up popUp2 (these are functions in the library of the apex with slightly different implementations), window.open, etc.

    popupURL
    function popupURL(a){html_PopUp(a,"winLov",800,600)}
    
    popUp
    function popUp(URL) {
     day = new Date();
     id = day.getTime();
     eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=600');");
     }
    
    popUp2
    function popUp2(b,a,c){day=new Date();pName=day.getTime();html_PopUp(b,pName,a,c)}
    
  • How to create a new page when the user activates a box?

    I guess this would be a checkbox.  I am looking for a way to create a user, select Create a new page when the user runs out of space in the text box that is given.  So if possible is a way to create a new page with a text box continuous when the user selects create it a new page check box.  Thank you.

    Yes, if you create a new page in the designer of the LC (page 2) and deselect the number of minutes, so that when the form is displayed at the start, it is not an instance of the page. While the click event of the button would be:

    _page2.addInstance(true);
    

    You can design page 2 with which opposes always desired.

    Hope that helps,

    Niall

  • run when the user presses ENTER

    Hello

    I have a program that scans a serial number and gives power.

    RightNow, I scan the serial number and the hit on the laview toolbar.

    But, I would like to program it so that when the user scans a number it would automatically generate results, without me hitting run or an OK button at all times.

    I enclose my vi below.

    So, anyone has any tip for me on how I could go about this?

    Thank you very much in advance,

    Yeshani

    Hello

    Here is a version that uses polling.  The entrance was there properties so that it is not until that you press ENTER.

    The reference is in fact a local variable.

    Local variables and the voting clerk aren't often mouse, but for "just a text entry" app, it should work well.

  • Flatten or lock a pdf form to be completed when the user presses the button "submit"

    Hello.  I have searched all over the net trying to figure this out.  I have a form that I created in LiveCycle and as I inserted a "REGULAR" button, with the following script:

    Create a variable to hold the document object

    var

    oDoc = event.target;

    oDoc.mailDoc({)

    bUI

    : true,

    cTo

    : "[email protected] " ",

    bassujetti

    : "New procedure - operator ' + TextField1.rawValue + "-ID" + TextField2.rawValue

    CSMG

    : "Attached is the form of the new procedure for the operator" + TextField1.rawValue + "-ID" + TextField2.rawValue + "." ,

    });

    This script is sending an e-mail to "[email protected]" and fill in the subject line and the body of the message with text and some elements of the fields in the PDF file.

    I want to have the locked PDF or flattened when the user clicks on the button submit, to ensure that the information in the PDF file is not modified once they submit.  I can't find any way to do this easily.  I found a script that will flatten the message (below), but I don't know how to add it to the email script that I pointed out above.  I don't want to add a second button to the form that I want to keep it as simple as possible for the user.

    Any suggestions that anyone might have would be greatly appreciated.  Thank you.

    Ryan

    Hello

    Check out this example:

    http://thelivecycle.blogspot.com/2010/02/mail-XFA-forms-as-protected-UnEditable.html

  • Full screen when the user presses tab pane

    Hello

    I have a tab pane in my application. When the user tab special tab I want to hide the tab pane and demand should be the mode display full screen. Is it possible to achieve with default tab pane?

    I solve this problem using the custom button instead of the default tab pane.

    Thank you

    Megha.

  • How to get an onChange event when the user clicks a button?

    Hello

    I'm new to APEX and have the following problem:

    Implementation:
    There are two text elements, one for the zip code and the other for the city.

    When you change the zip code, the city will be changed accordingly with the data from the database.

    I've implemented an "OnChange" in the zip code for this element.

    Problem: The on change event is executed only if the user leaves the text with a tab element or click on another piece of text.

    When it hits the "next page" button directly the city is not changed.

    Pointers for a solution please.


    Turalf

    Published by: Turalf on May 12, 2010 07:52

    Well, depends on how your button is built but, in any case, Javascript supports the onclick event on the element for each HTML.
    Model based buttons are often created as links using the indicator A, but which prevent you from adding an onclick on her event.
    In this case you must choose if you want to cancel the default action, or you prefer to perform the default action (the doSubmit in general) as well as the onclick event.
    The order of execution is
    1. the onclick event
    2. default action

    If you return false from the associated with onclick the function Manager, the default action will be canceled if you return true, he will be executed.

    Flavio

    ----
    http://oraclequirks.blogspot.com

  • How standards to enforce password complexity when the user password is chnaged

    Hello

    We currently have a function that imposes on users SQL password complexity. If we could use in some sort of logic to apply password changes the user of the Application (something equivalent to the password_verify_function in terms of database).

    Password complexity: 3 of the 4 are required - uppercase, lowercase, digital, special characters

    How do I achieve this in Ebussiness suite R12.

    Note: We do not use OAM (Oracle Access Manager) integrated with our applications.

    Please tell me an approach or is there another package or function defined where we customize according to the requirement.

    Kind regards
    Berch

    This can be implemented by using the profile options:

    How to set up password security? [564125.1 ID]

    For custom password security options, see:

    How to implement the profile (personal password access code) Option in the Oracle Applications 11i / R12 [ID 362663.1]

    Thank you
    Hussein

  • Autofocus TextField when the user presses the keys (and possible race condition)

    Someone tried to implement a device by which a TextField (or text box, I guess) automatically gets the focus when a user starts to type anything? It is very convenient to have something, at least with a phone model Qwerty, in certain situations. (A use case is where a list that is too long for the useful shortcuts, but the TextField object is used to implement a filtering mechanism that can reduce the data set to a reasonable size, and the user can then scroll just to find a target element).

    I've set up something using a KeyListener (calling requestFocus() for the TextField object) attached to the container Page, but there are problems with it.

    It's a question that the first keystroke does not render in the TextField object, since it has not a focus when the key was first struck.

    To solve that you can enter the key (event.unicode) and that insert into the TextField object, and then the following keys go on the field you want... but there is also a problem with that.

    If you type two or three buttons in quick succession, probably less than 50ms between them, you can see that even if the KeyListener gets each of them, the TextField object receives the second or, sometimes, the third, even if you can check that by the time second keyPressed/output signal arrives in your earpiece the TextField claims to have developed (TextField.focused is true).

    This seems like a bug, but maybe it's just a case of corner cascading who is inevitable, given its design... I'm not sure.

    If anyone can reproduce it, thanks for posting here. I'll do a test case to prove and will report it as a bug if you do.

    If anyone has a reliable and quality approach, please post here too! :-)

    P.S. for a good laugh, a code here that I did for my particular case, which seeks to avoid the race condition. As you can see, this is a great hack, but it works 100% reliable for me so far with a fairly comprehensive test (including the tests with the movement of the cursor, copy/paste, etc.). It's too complicated to analyze and ensure that it is really robust, however, but feel free to use... If you care enough. ;-)  http://pastebin.com/r2VUtPJC

    Have you tried setting the primaryKeyTarget it's inputRoute?

    https://developer.BlackBerry.com/native/reference/Cascades/bb__cascades__inputrouteproperties.html

    Has been added to the 10.1, which should do what you want.

    You can also achieve the same messing around with pre FocusPolicy 10.1, but it is much simpler.

  • How to call support bean method when the user moves out of field of af: inputListOfValues

    Hello

    I use jdev 11.1.2.4.

    I want to call a method of bean of support depending on the value selected in the af:inputListOfValues field.

    The requirement is similar as Frank Nimphius-Oracle has shown here https://blogs.oracle.com/jdevotnharvest/entry/how_to_notify_the_server but with component input list of values.

    The areas I want to call the method is

    <af:inputListOfValues id="appealNameId"
                          popupTitle="Search and Select: #{bindings.AppealName.hints.label}"
                          value="#{bindings.AppealName.inputValue}"
                          label="#{bindings.AppealName.hints.label}"
                          model="#{bindings.AppealName.listOfValuesModel}"
                          required="#{bindings.AppealName.hints.mandatory}"
                          columns="#{bindings.AppealName.hints.displayWidth}"
                          shortDesc="#{bindings.AppealName.hints.tooltip}"
                          binding="#{backingBeanScope.backing_Donation.appealNameId}"
                          autoSubmit="true" clientComponent="false">
                          <f:validator binding="#{bindings.AppealName.validator}"/>
                          <af:autoSuggestBehavior suggestedItems="#{backingBeanScope.backing_Donation.onSuggestAppeal}"/>
                          <af:clientListener method="onBlurTxtField" type="blur"/>
    </af:inputListOfValues>
    <af:serverListener type="onBlurNotifyServer"
                       method="#{backingBeanScope.backing_Donation.onBlurNotify}"/>
                          
    

    as you can see, af:serverListener is outside the af: inputListOfValues which is probably the reason why this isn't executing this method?

    public void onBlurNotify(ClientEvent clientEvent) {
       // get a hold of the input text component
       RichSelectOneChoice inputTxt =  (RichSelectOneChoice) clientEvent.getComponent(); 
       //do some work on it here (e.g. manipulating its readOnly state)
       //…
       //Get access to the payload
        
       Map  parameters = clientEvent.getParameters();
       System.out.println("SubmittedValue = "+parameters.get("submittedValue"));
       System.out.println("LocalValue =  "+parameters.get("localValue"));
       }
    

    I tried to put the serverListener tag inside the < af:inputListOfValues > but get error below

    "Listener server is not a valid child of list of values of the entry.


    any ideas please?

    Thank you

    As first, make sure you use a correct type for af:serverListener (Traore we are you queue in the javaScript onBlurTxtField function)

    If still not working, go directly to the source code page, and put af:serverListener 'manually', as a child for af:inputListOfValues.

    Because it is possible that these messages are false alarms...

  • How display the precedent when the browser shut down.

    Hi all

    I'm working on an application where user opens a screen and click a button when the user pressed this button, that it redirects to the browser of the phone with a specified binding. but I am facing a problem in that, when finally narrow the user's browser without complete specific action, my screen also poped off the coast of the user interface. My concern is that if the user close or close the browser without end action it must show previous screen. Please suggest me how to do this...

    Here is the code

    ButtonField checkUpdate = new ButtonField ("Update", ButtonField.CONSUME_CLICK);

    FieldChangeListener updateListener = new FieldChangeListener() {}
                
    ' Public Sub fieldChanged (field field, int context) {}

    Private private = Browser.getDefaultSession ();
    browserSession.displayPage ("http://www.xyz.com");

    }

    };

    checkUpdate.setChangeListener (updateListener);

    Some clarifications are needed before answering the question.

    requestBackground() is launched against the running application, not a screen.  If the application that will be 'requestBackground()' is your application (unless you did something very complicated!).  If you call requestBackground() in your application, then the BlackBerry OS will put your application at the bottom of the application stack and use the application stack that I described earlier to decide who to display screen of the application.

    In your application (in fact in any application), there is only a single screen at a time.  The BlackBerry OS keeps a stack of screen for your application, so the top of the screen hides those below.  When the screen from the top is popped, the one below is displayed.

    Now, back to your question:

    "can we set several background screen using the requestBackground() method?"

    I hope you understand now my answer, that is, you can set screens of your application in the background - but in reality, from the point of view of the user, you send a screen in the background, since that's all they see (users) don't see not the other displays on screen of the application stack until the top is popped.

  • How to perform an action when the user clicks on the "OK" button on a script by xfa.host.response

    Hello

    I have a script that when you exit a field without the user data that a script response is mentioned.

    When the user has entered the required data in the dialog box and click the OK button I wish that the data user in the field as a value.

    Please can someone tell how this is possible?

    The script is listed as follows:

    If this field is stopped without the user to enter data, the following message is displayed

    If

    (Employee_ID.rawValue == null)

    {

    XFA. Host.Response ("is a required field, enter your employee id');

    }

    Hello

    I think that this script will do the job:

    If (this.rawValue is nothing)

    {

    var id = xfa.host.response ("is a required field, enter your employee id');
    this.rawValue = id;
    }

    Yan.

Maybe you are looking for