I search for a possibility to start a rich dialog event with the function keys on the keyboard, e.g. to use F5 for refresh. I was successful to use the normal keys for characters or digits, but not for the function keys. How could this be possible?

asked 31.03.2011 at 04:57

Matthias%20Lang's gravatar image

Matthias Lang
(suspended)
accept rate: 0%


I did have the same problem and solved it like this:

I added buttons to the Rich Dialog panel for which I wanted to call events from function keys. For the buttons I added a normal event that handles the normal click of the button. Furthermore I added a ActionListener in the initialize() method of the panel that reacts on function keys and then invoke the click of the button programmatically.

private void initialize(){
    ...

    KeyStroke refresh = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
    this.registerKeyboardAction(new IActionListener(){
        public void actionPerformed(ActionEvent event){
            if(RefreshButton.isEnabled() && RefreshButton.isVisible()){
                RefreshButton.doClick();
            }
        }
    }, refresh, ULCRootPane.WHEN_IN_FOCUSED_WINDOW);
}

In the ActionListener we register a KeyStroke object for a key (in this case F5) as an action. The actionPerformed() method is then invoked when the user presses F5.

Instead of a button you can too use a hyper link and you even can make it invisible. If you do so, then do not forget to adapt the if part in my code.

link

answered 31.03.2011 at 07:32

Andras%20Fejer's gravatar image

Andras Fejer
(suspended)
accept rate: 100%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×40
×10

Asked: 31.03.2011 at 04:57

Seen: 2,027 times

Last updated: 31.03.2011 at 04:57