List of usage examples for javax.swing JToolBar add
public JButton add(Action a)
JButton
which dispatches the action. From source file:UndoManagerHelper.java
public static void main(String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager)); toolbar.add(undoButton); JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager)); toolbar.add(redoButton);/*from w ww . j a va2 s. c o m*/ frame.add(toolbar, BorderLayout.NORTH); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:UndoDrawing.java
public static void main(String args[]) { JFrame frame = new JFrame("Drawing Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); UndoableDrawingPanel drawingPanel = new UndoableDrawingPanel(); UndoManager manager = new UndoManager(); drawingPanel.addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); toolbar.add(UndoManagerHelper.getUndoAction(manager)); toolbar.add(UndoManagerHelper.getRedoAction(manager)); Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(drawingPanel, BorderLayout.CENTER); frame.setSize(300, 150);/*www . j av a2s . c o m*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton( new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText"))); toolbar.add(undoButton); Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150);//from w w w . ja v a 2 s. c o m frame.setVisible(true); }
From source file:BorderLayoutExample.java
public static void main(String[] args) { JFrame f = new JFrame(); JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); menubar.add(file);// w w w . j a v a 2s . c o m f.setJMenuBar(menubar); JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false); JButton bexit = new JButton(new ImageIcon("exit.png")); bexit.setBorder(new EmptyBorder(0, 0, 0, 0)); toolbar.add(bexit); f.add(toolbar, BorderLayout.NORTH); JToolBar vertical = new JToolBar(JToolBar.VERTICAL); vertical.setFloatable(false); vertical.setMargin(new Insets(10, 5, 5, 5)); JButton selectb = new JButton(new ImageIcon("a.png")); selectb.setBorder(new EmptyBorder(3, 0, 3, 0)); JButton freehandb = new JButton(new ImageIcon("b.png")); freehandb.setBorder(new EmptyBorder(3, 0, 3, 0)); JButton shapeedb = new JButton(new ImageIcon("c.png")); shapeedb.setBorder(new EmptyBorder(3, 0, 3, 0)); vertical.add(selectb); vertical.add(freehandb); vertical.add(shapeedb); f.add(vertical, BorderLayout.WEST); f.add(new JTextArea(), BorderLayout.CENTER); JLabel statusbar = new JLabel(" Statusbar"); statusbar.setPreferredSize(new Dimension(-1, 22)); statusbar.setBorder(LineBorder.createGrayLineBorder()); f.add(statusbar, BorderLayout.SOUTH); f.setSize(350, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton( new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText"))); toolbar.add(undoButton); JButton redoButton = new JButton( new RedoAction(manager, (String) UIManager.get("AbstractUndoableEdit.redoText"))); toolbar.add(redoButton);//w w w . j av a 2 s . c om Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:UndoableDrawingPanel.java
public static void main(String args[]) { JFrame frame = new JFrame("Drawing Sample2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); UndoableDrawingPanel drawingPanel = new UndoableDrawingPanel(); UndoManager manager = new UndoManager(); drawingPanel.addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager)); toolbar.add(undoButton); JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager)); toolbar.add(redoButton);//w w w .j ava 2 s . co m frame.add(toolbar, BorderLayout.NORTH); frame.add(drawingPanel, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:UndoDrawing.java
public static void main(String args[]) { JFrame frame = new JFrame("Drawing Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); UndoableDrawingPanel drawingPanel = new UndoableDrawingPanel(); UndoManager manager = new UndoManager(); drawingPanel.addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager)); toolbar.add(undoButton); JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager)); toolbar.add(redoButton);// w ww. ja v a2s. c o m Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(drawingPanel, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JToolBar toolbar = new JToolBar(JToolBar.VERTICAL); JButton selectb = new JButton(new ImageIcon("select.gif")); JButton freehandb = new JButton(new ImageIcon("freehand.gif")); JButton shapeedb = new JButton(new ImageIcon("shapeed.gif")); JButton penb = new JButton(new ImageIcon("pen.gif")); toolbar.add(selectb); toolbar.add(freehandb);/*from ww w . ja v a 2 s . c o m*/ toolbar.add(shapeedb); toolbar.add(penb); JFrame f = new JFrame(); f.add(toolbar, BorderLayout.WEST); f.setSize(250, 350); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("icon.gif"); Action action = new AbstractAction("Button Label", icon) { public void actionPerformed(ActionEvent evt) { }/*from w w w. ja va2 s .c o m*/ }; JButton c1 = new JButton(action); c1.setText(null); c1.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c1); JToggleButton c2 = new JToggleButton(action); c2.setText(null); c2.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c2); JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" }); c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width c3.setMaximumSize(c3.getMinimumSize()); toolbar.add(c3); }
From source file:DocumentModel.java
public static void main(String[] args) { final StyledDocument doc; final JTextPane textpane; JFrame f = new JFrame(); f.setTitle("Document Model"); JToolBar toolbar = new JToolBar(); JButton boldb = new JButton("bold"); JButton italb = new JButton("italic"); JButton strib = new JButton("strike"); JButton undeb = new JButton("underline"); toolbar.add(boldb); toolbar.add(italb);//w w w.j a v a2 s .c o m toolbar.add(strib); toolbar.add(undeb); f.add(toolbar, BorderLayout.NORTH); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JScrollPane pane = new JScrollPane(); textpane = new JTextPane(); textpane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); doc = textpane.getStyledDocument(); Style style = textpane.addStyle("Bold", null); StyleConstants.setBold(style, true); style = textpane.addStyle("Italic", null); StyleConstants.setItalic(style, true); style = textpane.addStyle("Underline", null); StyleConstants.setUnderline(style, true); style = textpane.addStyle("Strike", null); StyleConstants.setStrikeThrough(style, true); boldb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Bold"), false); } }); italb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Italic"), false); } }); strib.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Strike"), false); } }); undeb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Underline"), false); } }); pane.getViewport().add(textpane); panel.add(pane); f.add(panel); f.setSize(new Dimension(380, 320)); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }