Apr 29

Sometimes you need to get the currency symbol used for your currency in a different Locale. eg. In the US they use $, but a different Locale may use US$.

The Currency class can be used to not only get the currency symbol for a Locale, but also the currency symbol used for your currency in a different Locale.

Currency currency = Currency.getInstance(myLocale);
String symbol = currency.getSymbol(otherLocale);

written by objects \\ tags: , ,

Apr 28

Running the following will create a new keystore named myKeystore and password secret.


keytool -keystore myKeystore -genkey -keyalg RSA -alias mycert

written by objects \\ tags: , ,

Apr 26

Sometimes we want a key combination to perform a certain action regardless of what component has focus. Achieving this goal requires us to do two things.

  1. Add the required key stroke to the components key map
  2. Add the required action to the components action map

The “action key” is the link between the input map and the action map. When a key matches a key in the components input map the associated action key is used to look up the action in the action map.

The following example shows how to map an action to get performed whenever Ctrl-H is pressed within the focussed window.


// Get the KeyStroke for our hot key

KeyStroke ctrlH = KeyStroke.getKeyStroke(KeyEvent.VK_H, 
   InputEvent.CTRL_DOWN_MASK, true);

// Get the input map for our component
// In this case we are interested in key strokes in the focussed window

InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

// Map the key stroke to our "action key" (see below)

inputMap.put(ctrlH, "my_action");

// Get the action map for our component

ActionMap actionMap = panel.getActionMap();

// Add the required action listener to out action map

actionMap.put("my_action", actionListener);

written by objects \\ tags: , , ,