« Shortcuts » : différence entre les versions

De GENIUS
Aller à la navigation Aller à la recherche
(Page créée avec « TBW ... Return to the introduction ↑ Go to the next page → »)
 
Aucun résumé des modifications
 
(2 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
TBW ...
It exists two kind of methods, corresponding to different needs :
 
* <font color=#4169E1>setShortcut()</font>, useful to replace a mouse click
* <font color=#4169E1>setAccelerator()</font>, used to directly go to a functionnality
 
Let us explain it with the following example where we will have a File Menu with sub items to Load or Save a file.
 
Using <font color=#4169E1>setShortcut()</font> will allow to replace the mouse clicks as is:
 
* '''ALT+F''' to access to the File Menu
* '''ALT+L''' to access to the Load item
* '''ALT+S''' to access to the Save item
 
So, to load a file, you will have to type '''ALT+F''' then '''ALT+L''' (as you would have been to click two times using the mouse).
 
Using <font color=#4169E1>setAccelerator()</font> will allow to access directly to a functionnality (it is actually a shortcut):
 
* '''CTRL+L''' to access directly to the Load item
* '''CTRL+S''' to access directly to the Save item
 
Here is how to proceed ...
 
<syntaxhighlight lang="java">
// FileMenu initialization
fileMenu = new GMenu("File");
fileMenu.getJMenu().setMnemonic(KeyEvent.VK_F); // ALT+F to access to this menu
 
// Moad Item initialization
itemLoad = new GMenuItem("Load ...");
// ALT+L to access to it when File menu is active
itemLoad.setShortcut(KeyEvent.VK_L);
// CTRL+L to access directly to it
itemLoad.setAccelerator(KeyEvent.VK_L, ActionEvent.CTRL_MASK);
fileMenu.add(itemLoad);
 
itemSave = new GMenuItem("Save ...");
// ALT+S to access to it when File menu is active
itemSave.setShortCut(KeyEvent.VK_S);
// CTRL+S to access directly to it
itemSave.setAccelerator(KeyEvent.VK_S, ActionEvent.CTRL_MASK);
fileMenu.add(itemSave);
</syntaxhighlight>
 
 
[[File:Shortcuts.jpg]]
 


[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
[[Copy_&_paste|Go to the next page →]]
[[Copy_&_paste|Go to the next page →]]

Dernière version du 8 février 2018 à 14:22

It exists two kind of methods, corresponding to different needs :

  • setShortcut(), useful to replace a mouse click
  • setAccelerator(), used to directly go to a functionnality

Let us explain it with the following example where we will have a File Menu with sub items to Load or Save a file.

Using setShortcut() will allow to replace the mouse clicks as is:

  • ALT+F to access to the File Menu
  • ALT+L to access to the Load item
  • ALT+S to access to the Save item

So, to load a file, you will have to type ALT+F then ALT+L (as you would have been to click two times using the mouse).

Using setAccelerator() will allow to access directly to a functionnality (it is actually a shortcut):

  • CTRL+L to access directly to the Load item
  • CTRL+S to access directly to the Save item

Here is how to proceed ...

// FileMenu initialization
fileMenu = new GMenu("File");
fileMenu.getJMenu().setMnemonic(KeyEvent.VK_F); // ALT+F to access to this menu

// Moad Item initialization
itemLoad = new GMenuItem("Load ...");
// ALT+L to access to it when File menu is active
itemLoad.setShortcut(KeyEvent.VK_L);
// CTRL+L to access directly to it
itemLoad.setAccelerator(KeyEvent.VK_L, ActionEvent.CTRL_MASK);
fileMenu.add(itemLoad);

itemSave = new GMenuItem("Save ...");
// ALT+S to access to it when File menu is active
itemSave.setShortCut(KeyEvent.VK_S);
// CTRL+S to access directly to it
itemSave.setAccelerator(KeyEvent.VK_S, ActionEvent.CTRL_MASK);
fileMenu.add(itemSave);


Shortcuts.jpg


Return to the introduction ↑ Go to the next page →