A Complete JToolBar Usage Example : JToolBar « Swing « Java Tutorial






A Complete JToolBar Usage Example
import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;

public class ToolBarSample {
  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);

    
    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);
  }
}








14.57.JToolBar
14.57.1.JToolbar: Toolbars provide a quick access to the most frequently used commands.
14.57.2.A Complete JToolBar Usage ExampleA Complete JToolBar Usage Example
14.57.3.Create a vertical toolbar
14.57.4.Adding separator for JToolBarAdding separator for JToolBar
14.57.5.Add various buttons to the toolbar
14.57.6.Customizing Tool BarsCustomizing Tool Bars
14.57.7.Toolbar with CheckBoxToolbar with CheckBox
14.57.8.Swing ToolBar with Image button
14.57.9.Preventing a JToolbar Container from Floating
14.57.10.Highlighting Buttons in a JToolbar Container While Under the Cursor
14.57.11.Determining When a Floatable JToolBar Container Changes Orientation
14.57.12.Customizing JToolBar Look and Feel
14.57.13.This class represents a separator for the toolbar buttons.
14.57.14.ToolBar button