menuBar = new JMenuBar();
// Create a set of actions to use in both the menu and toolbar
DemoAction leftJustifyAction = new DemoAction("Left",
new ImageIcon("left.gif"), "Left justify text", 'L");
DemoAction rightJustifyAction = new DemoAction("Right",
new ImageIcon("right.gif"), "Right justify text", 'R");
DemoAction centerJustifyAction = new DemoAction("Center",
new ImageIcon("center.gif"), "Center justify text", 'M");
DemoAction fullJustifyAction = new DemoAction("Full",
new ImageIcon("full.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);
toolBar.addSeparator();
JComboBox combo = new JComboBox(fonts);
combo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try { pane.getStyledDocument().insertString(0,
"Font [" + ((JComboBox)e.getSource()).getSelectedItem() +
"] chosen!\n", null);
} catch (Exception ex) { ex.printStackTrace(); }
}
});
toolBar.add(combo);
// Disable one of the Actions
fullJustifyAction.setEnabled(false);