public ToolBarExample() {
menuBar = new JMenuBar();
// Create a set of actions to use in both the menu and toolbar
DemoAction leftJustifyAction = new DemoAction("Left", new ImageIcon(
"1.gif"), "Left justify text", 'L');
DemoAction rightJustifyAction = new DemoAction("Right", new ImageIcon(
"2.gif"), "Right justify text", 'R');
DemoAction centerJustifyAction = new DemoAction("Center",
new ImageIcon("3.gif"), "Center justify text", 'M');
DemoAction fullJustifyAction = new DemoAction("Full", new ImageIcon(
"4.gif"), "Full justify text", 'F');
JMenu formatMenu = new JMenu("Justify");
formatMenu.add(leftJustifyAction);
formatMenu.add(rightJustifyAction);
formatMenu.add(centerJustifyAction);
formatMenu.add(fullJustifyAction);
menuBar.add(formatMenu);
toolBar = new JToolBar("Formatting");
toolBar.add(leftJustifyAction);
toolBar.add(rightJustifyAction);
toolBar.add(centerJustifyAction);
toolBar.add(fullJustifyAction);
toolBar.addSeparator();
JLabel label = new JLabel("Font");
toolBar.add(label);
// Disable one of the Actions
fullJustifyAction.setEnabled(false);
}
public static void main(String s[]) {
ToolBarExample example = new ToolBarExample();
example.pane = new JTextPane();
example.pane.setPreferredSize(new Dimension(250, 250));
example.pane.setBorder(new BevelBorder(BevelBorder.LOWERED));
example.toolBar.setMaximumSize(example.toolBar.getSize());
JToolBar bar = new JToolBar();
JButton button1,button2,button3;
button1 = new JButton("pre");
button2 = new JButton("next");
button3 = new JButton("end");
bar.add(button1);
bar.add(button2);
bar.add(button3);
bar.setFloatable(false);
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
panel.add(bar);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("file");
JMenuItem exitMenuItem = new JMenuItem("退出");
menu.add(exitMenuItem);
menuBar.add(menu);