// Create a simple JToolBar with some buttons. protected JToolBar createToolBar() { JToolBar bar = new JToolBar(); // Add simple actions for opening & saving. bar.add(getOpenAction()).setText(""); bar.add(getSaveAction()).setText(""); bar.addSeparator(); // Add cut/copy/paste buttons. bar.add(textComp.getActionMap().get(DefaultEditorKit.cutAction)).setText(""); bar.add(textComp.getActionMap().get(DefaultEditorKit.copyAction)).setText(""); bar.add(textComp.getActionMap().get(DefaultEditorKit.pasteAction)).setText(""); return bar; }
// Create a JMenuBar with file & edit menus. protected JMenuBar createMenuBar() { JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); menubar.add(file); menubar.add(edit); file.add(getOpenAction()); file.add(getSaveAction()); file.add(new ExitAction()); edit.add(textComp.getActionMap().get(DefaultEditorKit.cutAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.copyAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.pasteAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.selectAllAction)); return menubar; }
// Add icons and friendly names to actions we care about. protected void makeActionsPretty() { Action a; a = textComp.getActionMap().get(DefaultEditorKit.cutAction); a.putValue(Action.SMALL_ICON, new ImageIcon("icons/cut.gif")); a.putValue(Action.NAME, "Cut"); a = textComp.getActionMap().get(DefaultEditorKit.copyAction); a.putValue(Action.SMALL_ICON, new ImageIcon("icons/copy.gif")); a.putValue(Action.NAME, "Copy"); a = textComp.getActionMap().get(DefaultEditorKit.pasteAction); a.putValue(Action.SMALL_ICON, new ImageIcon("icons/paste.gif")); a.putValue(Action.NAME, "Paste"); a = textComp.getActionMap().get(DefaultEditorKit.selectAllAction); a.putValue(Action.NAME, "Select All"); }