List of usage examples for javax.swing Action NAME
String NAME
To view the source code for javax.swing Action NAME.
Click Source Link
String
name for the action, used for a menu or button. From source file:LoadSync.java
public static void main(String args[]) { final String filename = "Test.html"; JFrame frame = new JFrame("Loading/Saving Example"); Container content = frame.getContentPane(); final JEditorPane editorPane = new JEditorPane(); editorPane.setEditable(false);// w ww. j a v a 2 s . c o m JScrollPane scrollPane = new JScrollPane(editorPane); content.add(scrollPane, BorderLayout.CENTER); editorPane.setEditorKit(new HTMLEditorKit()); JPanel panel = new JPanel(); // Setup actions Action loadAction = new AbstractAction() { { putValue(Action.NAME, "Load"); } public void actionPerformed(ActionEvent e) { doLoadCommand(editorPane, filename); } }; JButton loadButton = new JButton(loadAction); panel.add(loadButton); content.add(panel, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Action Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Action printAction = new PrintHelloAction(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu);//from w w w . j a v a 2s.c o m menu.add(new JMenuItem(printAction)); JToolBar toolbar = new JToolBar(); toolbar.add(new JButton(printAction)); JButton enableButton = new JButton("Enable"); ActionListener enableActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.setEnabled(true); } }; enableButton.addActionListener(enableActionListener); JButton disableButton = new JButton("Disable"); ActionListener disableActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.setEnabled(false); } }; disableButton.addActionListener(disableActionListener); JButton relabelButton = new JButton("Relabel"); ActionListener relabelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.putValue(Action.NAME, "Hello, World"); } }; relabelButton.addActionListener(relabelActionListener); JPanel buttonPanel = new JPanel(); buttonPanel.add(enableButton); buttonPanel.add(disableButton); buttonPanel.add(relabelButton); frame.setJMenuBar(menuBar); frame.add(toolbar, BorderLayout.SOUTH); frame.add(buttonPanel, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:PrintHelloAction.java
public static void main(String args[]) { JFrame frame = new JFrame("Action Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Action printAction = new PrintHelloAction(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu);/*from ww w .j av a 2 s. c o m*/ menu.add(new JMenuItem(printAction)); JToolBar toolbar = new JToolBar(); toolbar.add(new JButton(printAction)); JButton enableButton = new JButton("Enable"); ActionListener enableActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.setEnabled(true); } }; enableButton.addActionListener(enableActionListener); JButton disableButton = new JButton("Disable"); ActionListener disableActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.setEnabled(false); } }; disableButton.addActionListener(disableActionListener); JButton relabelButton = new JButton("Relabel"); ActionListener relabelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { printAction.putValue(Action.NAME, "Changed Action Value"); } }; relabelButton.addActionListener(relabelActionListener); JPanel buttonPanel = new JPanel(); buttonPanel.add(enableButton); buttonPanel.add(disableButton); buttonPanel.add(relabelButton); frame.setJMenuBar(menuBar); frame.add(toolbar, BorderLayout.SOUTH); frame.add(buttonPanel, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void mapAction(JComponent c, int condition, KeyStroke keyStroke, Action action) { Object key = action.getValue(Action.NAME); if (key == null) throw new IllegalArgumentException("The provided action must " + "have a name defined"); mapAction(c, condition, key, keyStroke, action); }
From source file:Main.java
public static void registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke) { comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, action.getValue(Action.NAME)); comp.getActionMap().put(action.getValue(Action.NAME), action); }
From source file:Main.java
/** * Adds a component action.//w w w .j av a 2s.c o m * * @param component * The compoennt to add the action to * @param action * The action to add */ public static void addComponentAction(final JComponent component, final Action action) { final InputMap imap = component .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap amap = component.getActionMap(); final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); imap.put(ks, action.getValue(Action.NAME)); amap.put(action.getValue(Action.NAME), action); }
From source file:Main.java
public static void installActions(JComponent comp, Action actions[], int condition) { ActionMap actionMap = comp.getActionMap(); InputMap inputMap = comp.getInputMap(condition); for (int i = 0; i < actions.length; i++) { String name = (String) actions[i].getValue(Action.NAME); actionMap.put(name, actions[i]); inputMap.put((KeyStroke) actions[i].getValue(Action.ACCELERATOR_KEY), name); }// w w w .ja v a2s .co m }
From source file:Main.java
/** * /*from w w w . j a v a 2 s .co m*/ * @param comp * @param action * @param condition - see {@link JComponent} * (WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,WHEN_IN_FOCUSED_WINDOW) */ public static void registerKeyBoardAction(JComponent comp, Action action, int condition) { comp.getInputMap(condition).put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), action.getValue(Action.NAME)); comp.getActionMap().put(action.getValue(Action.NAME), action); }
From source file:Main.java
public static HashMap<Object, Action> createActionTable(JTextComponent textComponent) { HashMap<Object, Action> actions = new HashMap<>(); Action[] actionsArray = textComponent.getActions(); for (int i = 0; i < actionsArray.length; i++) { Action a = actionsArray[i]; actions.put(a.getValue(Action.NAME), a); }//from w w w . ja v a 2s . co m return actions; }
From source file:ActionChangedListener.java
public void propertyChange(PropertyChangeEvent e) { String propertyName = e.getPropertyName(); System.out.println(propertyName); if (e.getPropertyName().equals(Action.NAME)) { String text = (String) e.getNewValue(); button.setText(text);//w w w.j a v a2s . co m button.repaint(); } else if (propertyName.equals("enabled")) { Boolean enabledState = (Boolean) e.getNewValue(); button.setEnabled(enabledState.booleanValue()); button.repaint(); } else if (e.getPropertyName().equals(Action.SMALL_ICON)) { Icon icon = (Icon) e.getNewValue(); button.setIcon(icon); button.invalidate(); button.repaint(); } }