MCPcopy Create free account
hub / github.com/benfry/processing4 / applyAction

Method applyAction

app/src/processing/app/ui/Toolkit.java:255–262  ·  view source on GitHub ↗

Apply an Action from something else (i.e. a JMenuItem) to a JButton. Swing is so absof ckinglutely convoluted sometimes. Do we really need half a dozen lines of boilerplate to apply a key shortcut to a button?

(Action action, JButton button)

Source from the content-addressed store, hash-verified

253 * half a dozen lines of boilerplate to apply a key shortcut to a button?
254 */
255 static public void applyAction(Action action, JButton button) {
256 button.setAction(action);
257 // use an arbitrary but unique name
258 String name = String.valueOf(action.hashCode());
259 button.getActionMap().put(name, action);
260 button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
261 .put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), name);
262 }
263
264
265 /**

Callers 1

FindReplaceMethod · 0.95

Calls 3

getValueMethod · 0.80
hashCodeMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected