Summary: This page describes the method to creates the font menu on which buttons,
combo boxes and a color chooser are arranged. |
Relevant major classes of Java SE: java.awt.*, java.awt.event.*, javax.swing.* |
Classes on this page: ButtonOfFontMenu |
1. Overview
If the other button, for example ButtonOfToggle, is pressed, the actionPerformed method generates calls the exec method of the ExecCommand for the command execution. In the case of this button, the actionPerformed
method shows only the font menu dialog. The command executions
are invoked by the buttons, the combo boxes or the color chooser on the
dialog.
Figure 1. Font menu botton and font menu dialog
2. Class ButtonOfFontMenu
return=>page top
public class ButtonOfFontMenu extends JButton implements ActionListener
Field
|
Description
|
dialog
|
JDialog dialog
The font menu dialog (Figure 1) which opens when the font menu button is pressed.
|
Method
|
Description
|
Constructor
|
public ButtonOfFontMenu(String commandName, String tip, JDialog dialog)
Creates a button with the specified text (commandName) on the button.
Parameters:
commandName - The command name.
tip - The text to be displayed in a tool tip.
dialog - The font menu dialog.
Processing:
Calls the following methods.
this.setActionCommand(commandName);
this.addActionListener(this);
this.setName(commandName);
this.setText(commandName);
this.setToolTipText(tip);
this.setStandardButtonStyle();
this.dialog=dialog;
|
Constructor
|
public ButtonOfFontMenu(String commandName, boolean setText, ImageIcon
imageIcon, String tip, JDialog dialog)
Creates a button with the specified imageIcon on the button. Display
the text (commandName) with the icon on the button, if
the setText is true.
Parameters:
commandName - The command name.
setText - If true, displays the commandName on the button.
imageIcon - The ImageIcon to be displayed on the button.
tip - The text to be displayed in a tool tip.
dialog - The font menu dialog.
Processing:
Calls the following methods.
super(imageIcon);
this.setActionCommand(commandName);
this.addActionListener(this);
this.setName(commandName);
if(setText) setText(commandName);
this.setToolTipText(tip);
this.setStandardButtonStyle();
this.dialog=dialog;
|
setStandardButtonStyle
|
public void setStandardButtonStyle()
Calls the following methods.
this.setBorder(this.raisedBorder);
this.setIconTextGap(0);
this.setHorizontalTextPosition(SwingConstants.CENTER );
this.setVerticalTextPosition(SwingConstants.BOTTOM );
this.setHorizontalAlignment(CENTER);
this.setFont(MenuConstants.MenuFont);
this.setBackground(null);
this.setForeground(Color.BLACK);
|
actionPerformed
|
public void actionPerformed(ActionEvent e)
∙ Shows the font menu dialog
this.dialog.setVisible(true)
∙ Sets the dialog position
this.dialog.setLocation(centerP);
|
createFontMenuButton
|
public static JButton createFontMenuButton(String commandName, int width,
String tip)
Parameters:
commandName - The command name.
width - The button width.
If the width<=0, then the button width is determined by using the TextLayout.
tip - The text to be displayed in a tool tip.
Processing:
∙ Creates a new JDialog object.
Creates the buttons, the combo boxes and the color chooser
of the font menu by the createFontStyleGroup method of the DrawMenu and adds them to the dialog (Figure 1).
∙ Creates a new button object by the first Constructor and returns
it.
|
|