List of usage examples for javax.swing JToolBar addSeparator
public void addSeparator()
From source file:ToolBarSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("JToolBar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true);/*from w ww.j a v a2 s .co m*/ JButton button = new JButton("button"); toolbar.add(button); toolbar.addSeparator(); toolbar.add(new JButton("button 2")); toolbar.add(new JComboBox(new String[] { "A", "B", "C" })); Container contentPane = frame.getContentPane(); contentPane.add(toolbar, BorderLayout.NORTH); JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(350, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolBar = new JToolBar("Still draggable"); toolBar.setFloatable(false);//from w w w . ja va2 s . co m toolBar.setRollover(true); toolBar.add(new JButton("New")); toolBar.addSeparator(); toolBar.add(new JButton("Open")); frame.add(toolBar, "North"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ToolBarTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JToolBar bar; bar = new JToolBar(); JToggleButton jb;// ww w . j av a 2 s . c o m for (int i = 0; i < 8; i++) { jb = new JToggleButton("" + i); bar.add(jb); if (i == 5) { bar.addSeparator(); } } contentPane.add(bar, BorderLayout.NORTH); frame.setSize(300, 300); frame.show(); }
From source file:MainClass.java
public static void main(String[] a) { final int STRING_POSITION = 1; Object buttonColors[][] = { { Color.RED, "RED" }, { Color.BLUE, "BLUE" }, { Color.GREEN, "GREEN" }, { Color.BLACK, "BLACK" }, null, // separator { Color.CYAN, "CYAN" } }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new TheActionListener(); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true);/*from w w w . j ava 2s. com*/ for (Object[] color : buttonColors) { if (color == null) { toolbar.addSeparator(); } else { Icon icon = MetalIconFactory.getTreeComputerIcon(); JButton button = new JButton(icon); button.setActionCommand((String) color[STRING_POSITION]); button.addActionListener(actionListener); toolbar.add(button); } } Action action = new ShowAction(toolbar); JButton button = new JButton(action); toolbar.add(button); Container contentPane = frame.getContentPane(); contentPane.add(toolbar, BorderLayout.NORTH); JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(350, 150); frame.setVisible(true); }
From source file:SwingToolBarSample.java
public static void main(String args[]) { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand()); }//from w w w.j a va 2 s.c o m }; JFrame frame = new JFrame("JToolBar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolbar = new JToolBar(); toolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); for (int i = 0, n = buttonColors.length; i < n; i++) { Object color[] = buttonColors[i]; if (color == null) { toolbar.addSeparator(); } else { Icon icon = new DiamondIcon((Color) color[COLOR_POSITION], true, 20, 20); JButton button = new JButton(icon); button.setActionCommand((String) color[STRING_POSITION]); button.addActionListener(actionListener); toolbar.add(button); } } Action action = new ActionMenuSample.ShowAction(frame); toolbar.add(action); Container contentPane = frame.getContentPane(); contentPane.add(toolbar, BorderLayout.NORTH); JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(350, 150); frame.setVisible(true); }
From source file:Main.java
public static void showFrameWithToolBar(String toolBarPosition) { JPanel gui = new JPanel(new BorderLayout()); JToolBar tb = new JToolBar(); gui.add(tb, toolBarPosition);//from ww w . j av a 2 s .c o m tb.add(new JButton("Button 1")); tb.add(new JButton("Button 2")); tb.addSeparator(); tb.add(new JButton("Button 3")); tb.add(new JCheckBox("Check 1", true)); JFrame f = new JFrame(toolBarPosition); f.setContentPane(gui); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setSize(400, 120); f.setVisible(true); }
From source file:Main.java
/** * Populates a {@link JToolBar} with the list items and {@link ActionMap}. * /*from www . j a v a 2 s. co m*/ * @param toolBar * @param actionMap * @param items */ public static void populate(JToolBar toolBar, ActionMap actionMap, List<?> items) { toolBar.setOpaque(false); for (Object item : items) { if (item instanceof Component) { toolBar.add((Component) item); } else if (item == null) { toolBar.addSeparator(); } else { final Action action = item instanceof Action ? (Action) item : actionMap.get(item); final AbstractButton button = createToolbarItem(action); toolBar.add(button); } } }
From source file:ToolBarTest.java
public ToolBarFrame() { setTitle("ToolBarTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add a panel for color change panel = new JPanel(); add(panel, BorderLayout.CENTER); // set up actions Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE); Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW); Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED); Action exitAction = new AbstractAction("Exit", new ImageIcon("exit.gif")) { public void actionPerformed(ActionEvent event) { System.exit(0);//from ww w . j a va 2 s.co m } }; exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit"); // populate tool bar JToolBar bar = new JToolBar(); bar.add(blueAction); bar.add(yellowAction); bar.add(redAction); bar.addSeparator(); bar.add(exitAction); add(bar, BorderLayout.NORTH); // populate menu JMenu menu = new JMenu("Color"); menu.add(yellowAction); menu.add(blueAction); menu.add(redAction); menu.add(exitAction); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationReportPanel.java
private JToolBar createToolBar() { JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false);/*www. ja v a2 s . c o m*/ toolbar.add(theActionManager.get("new")); toolbar.addSeparator(); toolbar.add(theActionManager.get("print")); return toolbar; }
From source file:Main.java
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;/* ww w . j a va 2s.c o m*/ }