Java Drawing DrawTop

Language

JP  US  UK

 

ComboBox

 H. Jyounishi, Tokyo Japan
 

Frame (Index), No frame                 version:0.3(latest)  

Summary: This page describes the way to creates a combo box object.
Relevant major classes of Java SE: java.awt.*, java.awt.event.*, javax.swing.*
Classes on this page:ComboBox, ComboBoxAction

1. Class ComboBox 戻る=>page top
public class ComboBox extends JComboBox
Field Description
action ComboBoxAction action
ComboBoxAction object.

Method Description
Constructor public ComboBox(String commandName, String[] items, String tip)
Parameters:
commandName - The command name.
items - The array of the JComboBox items.
tip - The text to be displayed in a tool tip.
Processing:
Calls the following methods.

this.setActionCommand(commandName);
this.addActionListener(this.action);
this.setName(commandName);
this.setToolTipText(tip);

activateListener public void activateListener(boolean activate)
If the activate is true, then adds the ComboBoxAction to this object as an ActionListener,
otherwise removes the ComboBoxAction from this object.
: If the setSelectedItem or setSelectedIndex method of the JComboBox is called, the action occurs and the actionPerformed method is called to execute a command. This behavior may be inconvenient in some situation. This method provides the function to restrain the occurrence of the action by adding or removing the ActionListener.
=>FontStyle.setFontStyleToMenu
isActionListener private boolean isActionListener(ActionListener listener)
Return true if the ComboBoxAction is added to this object.
createFontFamily
ComboBox
(static)
public static JComboBox createFontFamilyComboBox(String name)
Parameters:
name - The command name
Processing:
Create a new ComboBox object for selecting a font family.


ComboBox for font families

createFontSizeComboBox
(static)
public static JComboBox createFontSizeComboBox(String name)
Parameters:
name - The command name
Processing:
Create a new ComboBox object for selecting a font size.

ComboBox for font sizes



2. ComboBoxAction 戻る=>page top
class ComboBoxAction extends AbstractAction

Method

Description

actionPerformed public void actionPerformed(ActionEvent e)
∙ The action command

The action command can be got by the following line.
String commandName=e.getActionCommand();

∙ Generates the command

The commandId can be got by the getCommandId method with the parameter of the commandName. The command parameter can be got by the getSelectedItem method of the JComboBox.
Then generates a Command object using the commandId and the command paremter, and calls the exec method of the ExecCommand.



Copyright (c) 2009-2013
All other trademarks are property of their respective owners.