List of usage examples for javax.swing JToolBar add
public JButton add(Action a)
JButton
which dispatches the action. From source file:MainClass.java
public MainClass() { super();/* w w w .jav a2 s .c om*/ JToolBar urlToolBar = new JToolBar(); mURLField = new JTextField(40); urlToolBar.add(new JLabel("Location:")); urlToolBar.add(mURLField); frame.add(urlToolBar, BorderLayout.NORTH); mEditorPane = new JEditorPane(); mEditorPane.setEditable(false); frame.add(new JScrollPane(mEditorPane), BorderLayout.CENTER); openURL("http://www.java2s.com"); mURLField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { openURL(ae.getActionCommand()); } }); mEditorPane.addHyperlinkListener(new LinkActivator()); setSize(500, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
Main() { gui.setBorder(new EmptyBorder(2, 3, 2, 3)); String userDirLocation = System.getProperty("user.dir"); File userDir = new File(userDirLocation); // default to user directory fileChooser = new JFileChooser(userDir); Action open = new AbstractAction("Open") { @Override/* www. j a v a 2 s. com*/ public void actionPerformed(ActionEvent e) { int result = fileChooser.showOpenDialog(gui); if (result == JFileChooser.APPROVE_OPTION) { try { File f = fileChooser.getSelectedFile(); FileReader fr = new FileReader(f); output.read(fr, f); fr.close(); } catch (Exception ex) { ex.printStackTrace(); } } } }; Action save = new AbstractAction("Save") { @Override public void actionPerformed(ActionEvent e) { int result = fileChooser.showSaveDialog(gui); System.out.println("Not supported yet."); } }; JToolBar tb = new JToolBar(); gui.add(tb, BorderLayout.PAGE_START); tb.add(open); tb.add(save); gui.add(new JScrollPane(output)); }
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);/*w ww . j ava 2 s.c o 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:ToolBarwithCheckBox.java
public ToolbarPanel() { setLayout(new BorderLayout()); JToolBar toolbar = new JToolBar(); for (int i = 1; i < 4; i++) { JCheckBox cbox = new JCheckBox("Checkbox #" + i); toolbar.add(cbox); cbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox source = (JCheckBox) (e.getSource()); System.out.println("Toolbar " + source.getText()); }/*w ww .j av a2s.co m*/ }); } add(toolbar, BorderLayout.NORTH); }
From source file:org.jax.bham.test.PhenotypeEffectPlotPanel.java
/** * Constructor//from w w w.j a v a2 s.c o m * @param phenotypeDataSource * the phenotype data source * @param strainGroups * the strain groupings */ public PhenotypeEffectPlotPanel(PhenotypeDataSource phenotypeDataSource, Map<String, ? extends Collection<String>> strainGroups) { super(new BorderLayout()); this.chartPanel = new ChartPanel(null, true); this.showIndividualStrainEffectsCheckBox = new JCheckBox("Show Individual Strain Effects", false); this.phenotypeDataSource = phenotypeDataSource; this.phenotypeData = phenotypeDataSource.getPhenotypeData(); this.strainGroups = strainGroups; this.updateChart(); JToolBar toolBar = new JToolBar(); toolBar.add(this.showIndividualStrainEffectsCheckBox); this.showIndividualStrainEffectsCheckBox.addItemListener(new ItemListener() { /** * {@inheritDoc} */ public void itemStateChanged(ItemEvent e) { PhenotypeEffectPlotPanel.this.updateChart(); } }); this.add(toolBar, BorderLayout.PAGE_START); this.add(this.chartPanel, BorderLayout.CENTER); }
From source file:SiteFrame.java
public SiteManager() { super("Web Site Manager"); setSize(450, 250);/*from ww w . j a v a 2 s. c om*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container contentPane = getContentPane(); JToolBar jtb = new JToolBar(); jtb.add(new CutAction(this)); jtb.add(new CopyAction(this)); jtb.add(new PasteAction(this)); contentPane.add(jtb, BorderLayout.NORTH); // Add our LayeredPane object for the internal frames. desktop = new JDesktopPane(); contentPane.add(desktop, BorderLayout.CENTER); addSiteFrame("Sample"); }
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();// w w w . ja v a 2 s. com // 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; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationReportPanel.java
private JToolBar createToolBar() { JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false);//from w w w.ja v a 2 s .co m toolbar.add(theActionManager.get("new")); toolbar.addSeparator(); toolbar.add(theActionManager.get("print")); return toolbar; }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolBar = new JToolBar(); Action a = new AbstractAction("Demo") { public void actionPerformed(ActionEvent e) { System.out.println("Action taken."); }//from ww w.ja va2 s .co m }; JButton b = toolBar.add(a); b.setText("Demo Button"); b.setToolTipText("Press me to take action."); JMenu mainMenu = new JMenu("Menu"); JMenuItem mi = mainMenu.add(a); mi.getAccessibleContext().setAccessibleName("Menu item"); JMenuBar mb = new JMenuBar(); mb.add(mainMenu); setJMenuBar(mb); JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.setPreferredSize(new Dimension(200, 100)); pane.add(toolBar, BorderLayout.NORTH); setContentPane(pane); pack(); setVisible(true); }
From source file:SwingToolBarDemo.java
protected void addButtons(JToolBar toolBar) { JButton button = null;/*from w w w . j ava2 s.c om*/ //first button button = makeNavigationButton("Back24", PREVIOUS, "Back to previous something-or-other", "Previous"); toolBar.add(button); //second button button = makeNavigationButton("Up24", UP, "Up to something-or-other", "Up"); toolBar.add(button); //third button button = makeNavigationButton("Forward24", NEXT, "Forward to something-or-other", "Next"); toolBar.add(button); }