this.setPreferredSize(new Dimension(640, 480)); this.addMouseListener(mouseHandler); this.addMouseMotionListener(mouseHandler); this.add(new MoveButton("\u2190", KeyEvent.VK_LEFT, -DELTA, 0)); this.add(new MoveButton("\u2191", KeyEvent.VK_UP, 0, -DELTA)); this.add(new MoveButton("\u2192", KeyEvent.VK_RIGHT, DELTA, 0)); this.add(new MoveButton("\u2193", KeyEvent.VK_DOWN, 0, DELTA)); final int dx, final int dy) { super(name); this.k = KeyStroke.getKeyStroke(code, 0); this.dx = dx; this.dy = dy; ControlPanel.this.getInputMap(WHEN_IN_FOCUSED_WINDOW) .put(k, k.toString()); ControlPanel.this.getActionMap() .put(k.toString(), new AbstractAction() { JFrame f = new JFrame("LinePanel"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.add(new ControlPanel(), BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true);
Action action = null; do { action = action == null ? aMap.get(DefaultEditorKit.deletePrevCharAction) : null; aMap.remove(DefaultEditorKit.deletePrevCharAction); aMap = aMap.getParent(); } while (aMap != null); aMap = getActionMap(); InputMap iMap = getInputMap(); KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0, false); iMap.put(keyStroke, "delete"); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.SHIFT_MASK, false); iMap.put(keyStroke, "delete"); aMap.put("delete", action); aMap.put(FIND, action); keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK, false); iMap.put(keyStroke, FIND); aMap.put(FIND_NEXT, FindReplaceUtility.FIND_ACTION); aMap.put(FIND_PREVIOUS, FindReplaceUtility.FIND_ACTION); aMap.put("TextEditor-tabAction", action); aMap.put("TextEditor-shiftTabAction", action); getActionMap().put(REPLACE, action); getActionMap().put(AUTO_INDENT, action);
@Override public Object invoke(Object o, Method method, Object[] args) throws Throwable { if (method.getName().equals("windowEnteredFullScreen")) { putValue(NAME, LocalisationHelper.getString("main_frame_menuitem_leave_fullscreen")); putValue(SHORT_DESCRIPTION, LocalisationHelper.getString("main_frame_menuitem_hint_leave_fullscreen")); gcViewer.getDesktopPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "leaveFullScreen"); gcViewer.getDesktopPane().getActionMap().put("leaveFullScreen", OSXFullScreen.this); } if (method.getName().equals("windowExitedFullScreen")) { putValue(NAME, LocalisationHelper.getString("main_frame_menuitem_enter_fullscreen")); putValue(SHORT_DESCRIPTION, LocalisationHelper.getString("main_frame_menuitem_hint_enter_fullscreen")); gcViewer.getDesktopPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); gcViewer.getDesktopPane().getActionMap().remove("leaveFullScreen"); } return null; } });
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); p.add(f); frame.add(p); frame.pack(); frame.setVisible(true); autoSuggestionPopUpWindow.setOpacity(opacity); suggestionsPanel.setLayout(new GridLayout(0, 1)); suggestionsPanel.setBackground(popUpBackground); textField.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), "Down released"); textField.getActionMap().put("Down released", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) {//focuses the first label on popwindow suggestionsPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), "Down released"); suggestionsPanel.getActionMap().put("Down released", new AbstractAction() { int lastFocusableIndex = 0; getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), "Enter released"); getActionMap().put("Enter released", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) {
ActionMap actionMap = getActionMap(); int condition = JComponent.WHEN_IN_FOCUSED_WINDOW; InputMap inputMap = getInputMap(condition); inputMap.put(direction.getKeyStroke(), direction.getText()); actionMap.put(direction.getText(), new MyArrowBinding(direction.getText())); ArrowTest mainPanel = new ArrowTest(); JFrame frame = new JFrame("ArrowTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)), DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)), LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
protected JDialog createDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); JDialog dialog = new JDialog(frame, ("Select Font"), true); Action okAction = new DialogOKAction(dialog); Action cancelAction = new DialogCancelAction(dialog); JButton okButton = new JButton(okAction); okButton.setFont(DEFAULT_FONT); JButton cancelButton = new JButton(cancelAction); cancelButton.setFont(DEFAULT_FONT); JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(2, 1)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10)); ActionMap actionMap = buttonsPanel.getActionMap(); actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction); actionMap.put(okAction.getValue(Action.DEFAULT), okAction); InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT)); inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT)); JPanel dialogEastPanel = new JPanel(); dialogEastPanel.setLayout(new BorderLayout()); dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST); dialog.pack(); dialog.setLocationRelativeTo(frame); return dialog; }
Container contentPane = getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add( nullTraversalKeys() ); contentPane.add( writeYourOwnAction() ); contentPane.add( useKeyListener() ); contentPane.add( addTraversalKeys() ); textArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); textArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); JScrollPane scrollPane = new JScrollPane( textArea ); InputMap im = textArea.getInputMap(); KeyStroke tab = KeyStroke.getKeyStroke("TAB"); textArea.getActionMap().put(im.get(tab), new TabAction(true)); KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB"); im.put(shiftTab, shiftTab); textArea.getActionMap().put(im.get(shiftTab), new TabAction(false)); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
private JFrame f = new JFrame("FullScreenTest"); private Action exit = new AbstractAction(EXIT) { this.add(b); f.getRootPane().setDefaultButton(b); this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), EXIT); this.getActionMap().put(EXIT, exit); this.addMouseMotionListener(new MouseAdapter() { FullScreenTest.this.setToolTipText( "("+ e.getX() + "," + e.getY() + ")"); GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice dev = env.getDefaultScreenDevice(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBackground(Color.darkGray); f.setResizable(false); f.setUndecorated(true); f.add(this); f.pack(); dev.setFullScreenWindow(f);
public void run() { JFrame frame = new JFrame(pTitle); frame.getRootPane().getActionMap().put("window-close", new AbstractAction() { public void actionPerformed(ActionEvent e) { Window window = SwingUtilities.getWindowAncestor((Component) e.getSource()); window.setVisible(false); window.dispose(); } }); frame.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "window-close"); frame.addWindowListener(new ExitIfNoWindowPresentHandler()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationByPlatform(true); JPanel pane = new JPanel(new BorderLayout()); JScrollPane scroll = new JScrollPane(pImage != null ? new ImageLabel(pImage) : new JLabel("(no image data)", JLabel.CENTER)); scroll.setBorder(null); pane.add(scroll); frame.setContentPane(pane); frame.pack(); frame.setVisible(true); } });
public static void addKeyBinding(JComponent comp, KeyStroke key, String id, Action action) { comp.getInputMap().put(key, id); comp.getActionMap().put(id, action); }
public static void installAutoTabAction(JTextComponent tComp) { tComp.getActionMap().put("GroovyFilter-autoTab", AUTO_TAB_ACTION); KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); tComp.getInputMap().put(keyStroke, "GroovyFilter-autoTab"); }
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 500); setLayout(new BorderLayout()); setVisible(true); panel = new JPanel(); panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0), "forward"); panel.getActionMap().put("forward", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { add(panel, BorderLayout.CENTER);
@PostConstruct protected void init() { final KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); final String actionName = "org.wiztools.restclient:ADDRESS_FOCUS"; jcb_url.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(ks, actionName); jcb_url.getActionMap().put(actionName, new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { jl_url.setLabelFor(jcb_url); jl_url.setDisplayedMnemonic('u'); rest_ui.getFrame().getRootPane().setDefaultButton(jb_request); rest_ui.getFrame().getRootPane().setDefaultButton(jb_request); jb_request.addActionListener(new ActionListener() { @Override
this.getProxy().getActionMap().put(undoIdentifier, new AbstractAction(undoIdentifier) { @Override this.getProxy().getInputMap().put(KeyStroke.getKeyStroke("control Z"), undoIdentifier); this.getProxy().getActionMap().put(redoIdentifier, new AbstractAction(redoIdentifier) { @Override this.getProxy().getInputMap().put(KeyStroke.getKeyStroke("control Y"), redoIdentifier); am.put(key, new SilentDeleteTextAction(key, am.get(key))); am.put(key, new SilentDeleteTextAction(key, am.get(key)));
private void unregisterListeners() { KeyStroke refreshKey = KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK, true); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(refreshKey); getActionMap().remove("refresh"); // NOI18N resetKeyboardActions(); }
@Override public void installCG(SComponent component) { super.installCG(component); final STabbedPane tab = (STabbedPane) component; InputMap inputMap = new InputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK, false), "previous"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK, false), "next"); tab.setInputMap(SComponent.WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); Action action = new MyAbstractAction(tab); ActionMap actionMap = new ActionMap(); actionMap.put("previous", action); actionMap.put("next", action); tab.setActionMap(actionMap); }
@Override protected ActionMap createViewActionMap(View v) { ActionMap intermediateMap = new ActionMap(); intermediateMap.put(FocusWindowAction.ID, new FocusWindowAction(v)); ActionMap vMap = model.createActionMap(this, v); vMap.setParent(intermediateMap); intermediateMap.setParent(getActionMap(null)); return vMap; }
private static final String TEXT_SUBMIT = "text-submit"; private static final String INSERT_BREAK = "insert-break"; ... private void initialize() { InputMap input = inputTextArea.getInputMap(); KeyStroke enter = KeyStroke.getKeyStroke("ENTER"); KeyStroke shiftEnter = KeyStroke.getKeyStroke("shift ENTER"); input.put(shiftEnter, INSERT_BREAK); // input.get(enter)) = "insert-break" input.put(enter, TEXT_SUBMIT); ActionMap actions = inputTextArea.getActionMap(); actions.put(TEXT_SUBMIT, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { submitText(); } }); } ... private void submitText() { // TODO }
copyItem.setAction(component.getActionMap().get(DefaultEditorKit.copyAction)); copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); copyItem.setMnemonic('C'); copyItem.setText(I18n.valueByKey("CONTEXT_MENU_COPY")); selectAllItem.setAction(component.getActionMap().get(DefaultEditorKit.selectAllAction)); selectAllItem.setText(I18n.valueByKey("CONTEXT_MENU_SELECT_ALL")); I18nView.addComponentForKey("CONTEXT_MENU_SELECT_ALL", selectAllItem); selectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); selectAllItem.setMnemonic('A'); clearItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK)); clearItem.setMnemonic('E');