jbcl.control Package
java.lang.Object +----java.awt.Component +----java.awt.Container +----javax.swing.JComponent +----com.borland.jbcl.view.BeanPanel +----com.borland.jbcl.control.BevelPanel +----com.borland.jbcl.control.ButtonBar +----com.borland.jbcl.control.NavigatorControl
Variables Constructors Properties Methods Event Listeners
Implements BlackBox, ImageObserver, MenuContainer, Serializable
A ButtonBar
object is a container for buttons. You add buttons to the ButtonBar
using the
addImageButton()
or
addTextButton()
methods. The ButtonBar
defaults to a horizontal bar with buttons that are spaced four pixels apart. You override these defaults by setting the
alignment
property to set the display alignment and the addSpace()
method to specify a different spacing between buttons.
When a button on the ButtonBar
is clicked, an ActionEvent
is sent to all registered
listeners. The ID associated with the ActionEvent
contains the ID of the button that was
clicked. When notified of the event, each listener can act on the event, or pass it on to another
method for handling.
For information on using and configuring the ButtonBar
in the UI Designer, see
Using a ButtonBar.
This example is a simple ButtonBar
application, of which this code is taken from the Frame
object. This application displays a ButtonBar
with three buttons with images and
two buttons labelled with text. In the central area of the Frame are a button labelled Disabler and a
Toggler checkbox.
The image buttons represent toolbar icons of File Open, File Save, and Help, however, they don't have any actual functionality associated with them. The Disable button also does not have any functionality associated with it, however, it demonstrates how a button can be disabled. Clicking the Disabler button in the central area of the Frame disables (dims) the File Open icon and enables the Disable text button. Clicking the Disabler button again reverses the disablement and enablement of both buttons. Finally, the Toggle checkbox is a standard checkbox whose value can also be toggled by clicking the Toggler button.
package buttonbarsample;
import java.awt.*;
import java.awt.event.*;
import com.borland.jbcl.control.*;
import com.borland.jbcl.layout.*;
public class Frame1 extends DecoratedFrame {
BorderLayout borderLayout1 = new BorderLayout();
XYLayout xYLayout2 = new XYLayout();
BevelPanel bevelPanel1 = new BevelPanel();
ButtonBar buttonBar = new ButtonBar();
StatusBar statusBar = new StatusBar();
CheckboxControl checkboxControl1 = new CheckboxControl();
ButtonControl buttonControl1 = new ButtonControl();
//Construct the frame
public Frame1() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
buttonBar.setBevelOuter(BevelPanel.LOWERED);
buttonBar.setBevelInner(BevelPanel.LOWERED);
buttonBar.setButtonOrientation(com.borland.jbcl.util.Orientation.VERTICAL);
buttonBar.setButtonType(ButtonBar.IMAGE_ONLY);
buttonBar.setHgap(3);
buttonBar.setLabels(new String[] {"File", "Close", "Help", "Disable", "Toggler"});
buttonBar.setVgap(2);
buttonBar.addActionListener(new Frame1_buttonBar_actionAdapter(this));
checkboxControl1.setLabel("Toggle");
buttonControl1.setLabel("Disabler");
buttonControl1.addActionListener(new Frame1_buttonControl1_actionAdapter(this));
buttonBar.setImageBase("image");
buttonBar.setImageNames(new String[] {"openFile.gif", "closeFile.gif", "help.gif"});
buttonBar.setButtonEnabled(3, false);
bevelPanel1.setLayout(xYLayout2);
this.add(buttonBar, BorderLayout.NORTH);
this.add(statusBar, BorderLayout.SOUTH);
this.add(bevelPanel1, BorderLayout.CENTER);
bevelPanel1.add(checkboxControl1, new XYConstraints(284, 77, 83, 38));
bevelPanel1.add(buttonControl1, new XYConstraints(22, 91, -1, -1));
}
//File | Exit action performed
public void fileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void helpAbout_actionPerformed(ActionEvent e) {
}
void buttonControl1_actionPerformed(ActionEvent e) {
buttonBar.setButtonEnabled(0, !buttonBar.isButtonEnabled(0));
buttonBar.setButtonEnabled(3, !buttonBar.isButtonEnabled(3));
}
void buttonBar_actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Toggler"))
checkboxControl1.setChecked(!checkboxControl1.isChecked());
}
}
class Frame1_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_buttonControl1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.buttonControl1_actionPerformed(e);
}
}
class Frame1_buttonBar_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_buttonBar_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.buttonBar_actionPerformed(e);
}
}
protected transient ActionMulticaster actionMulticaster
protected BorderItemPainter border
public static final int IMAGE_ONLY = 2A
buttonType
constant for buttons displaying (only) images.
protected transient MouseMotionMulticaster mouseMotionMulticaster
protected transient MouseMulticaster mouseMulticaster
protected boolean needsRebuild
public static final int TEXT_AND_IMAGE = 3A
buttonType
constant for buttons that display both text and an image.
public static final int TEXT_ONLY = 1A
buttonType
constant for buttons that display text only.
public ButtonBar()Constructs a
ButtonBar
component with the default settings of
TEXT_AND_IMAGE
and HORIZONTAL
orientation.
Buttons are added to the ButtonBar
from left to right for a horizontal
ButtonBar
.
public int getAlignment() public void setAlignment(int alignment)Stores the alignment for this
ButtonBar
. Accepted values for alignment
are defined in
Alignment variables
.
public int getButtonAlignment() public void setButtonAlignment(int a)Determines how the label and the image are aligned on the buttons. Accepted values for
alignment
are defined in
Alignment variables
.
public int getButtonOrientation() public void setButtonOrientation(int o)Stores the orientation of the button graphics in relation to the button text. Valid values are
Orientation.HORIZONTAL
or Orientation.VERTICAL
.
To change the orientation of the ButtonBar
itself, change the ButtonBar's
layout.
For example, change the following (programmatically)
buttonBar1.setLayout(new GridLayout(1,0))
to
buttonBar1.setLayout(new GridLayout(0,1))
public int getButtonType() public void setButtonType(int buttonType)Stores the type of the
ButtonBar
. Accepted values are ButtonBar
constants of
TEXT_ONLY
, IMAGE_ONLY
, and TEXT_AND_IMAGE
.
public void setEnabled(boolean enabled)Write-only property that enables or disables the
ButtonBar
.
public int getHgap() public void setHgap(int gap)Specifies the horizontal gap setting for this
ButtonBar
, in pixels.
public String getImageBase() public void setImageBase(String ib)Specifies the base location for finding the images specified in the
imageNames
property. The location can be a Universal Resource Locator (URL), a relative path, or an
absolute path prefix.
public boolean isImageFirst() public void setImageFirst(boolean first)Defines how label and image are arranged: either true for image on left/top or false for image on right/bottom
public String[] getImageNames() public void setImageNames(String[] imageNames)Specifies the array of
String
names for the images displayed on the
ButtonBar
.
public String[] getLabels() public void setLabels(String[] labels)Specifies the array of
String
names for the buttons in the ButtonBar
.
The array represents the buttons to be added (replacing old) to the ButtonBar
.
These labels also distinguish the added buttons as the ActionCommand
in the
ActionPerformed
method on the ButtonBar
.
public void setOpaque(boolean opaque)Write-only property that determines whether the
ButtonBar
is opaque or not.
public Dimension getPreferredSize()Stores the preferred dimensions to use when drawing the
ButtonBar
.
public boolean isShowRollover() public void setShowRollover(boolean showRollover)Enables or disables the repainting of the rollover item. The rollover item is the item that currently has the mouse floating over it. If an
ItemPainter
plugged into
the ButtonBar
ignores the ROLLOVER bit, this property will have no effect.
By default, this property is false.
public int getVgap() public void setVgap(int gap)Stores the vertical gap setting, in pixels, for this
ButtonBar
.
protected Component addImageButton(Image image, String label, String command)Creates a new
ImageButton
with the properties specified in its parameters and adds it to the ButtonBar
.
Parameters:
image
label
command
actionId
associated with this button by which you can later refer to this button.
protected Component addSpace()Adds a space 4 pixels wide between each button on the
ButtonBar
object, repaints the ButtonBar
object, and returns the Component
object. To specify the amount of space between buttons, use addSpace(int).
protected Component addSpace(int gap)Adds the specified amount of space (in pixels) between each button then repaints the
ButtonBar
.
protected Component addTextButton(String label, String command)Adds a button to the
ButtonBar
that displays a text string specified by label
and assigns it the actionId specified by actionId
. The actionId is any integer value by which you can later refer to this button and keep track of it. When a button is pressed, the actionEvent
occurs, and registered listeners of the ButtonBar
are notified. Using the actionId
, listeners can determine exactly which button was pressed and what actions should take place.
Parameters:
label
command
actionId
associated with this button by which you can later refer to this button.
protected void assureImages()
public void doLayout()
Overrides: java.awt.Container.doLayout()
protected void invalidateButtons()
protected void invalidateImages()
public boolean isButtonEnabled(int index)Returns whether the button at the specified position index is enabled or not.
public boolean isButtonEnabled(String label)Returns whether the button with the specified
label
is enabled or not.
public boolean isButtonVisible(int index)Returns whether the button at the specified position index is visible or not.
public boolean isButtonVisible(String label)Returns whether the button with the specified
label
is visible or not.
protected void rebuild()Rebuilds the
ButtonBar
.
public void setButtonEnabled(int index, boolean enabled)Enables or disables a particular button by index.
Parameters:
index
enabled
public void setButtonEnabled(String label, boolean enabled)Enables or disables a particular button by label.
Parameters:
label
enabled
public void setButtonVisible(int index, boolean visible)Sets a particular button to visible or invisible by index
Parameters:
index
visible
public void setButtonVisible(String label, boolean visible)Sets a particular button to visible or invisible by label
Parameters:
label
visible
public synchronized void addActionListener(ActionListener l) public synchronized void removeActionListener(ActionListener l)
public void addAncestorListener(javax.swing.event.AncestorListener ) public void removeAncestorListener(javax.swing.event.AncestorListener )
public synchronized void addComponentListener(java.awt.event.ComponentListener ) public synchronized void removeComponentListener(java.awt.event.ComponentListener )
public synchronized void addContainerListener(java.awt.event.ContainerListener ) public synchronized void removeContainerListener(java.awt.event.ContainerListener )
public synchronized void addFocusListener(java.awt.event.FocusListener ) public synchronized void removeFocusListener(java.awt.event.FocusListener )
public synchronized void addInputMethodListener(java.awt.event.InputMethodListener ) public synchronized void removeInputMethodListener(java.awt.event.InputMethodListener )
public synchronized void addKeyListener(java.awt.event.KeyListener ) public synchronized void removeKeyListener(java.awt.event.KeyListener )
public void addMouseListener(MouseListener l) public void removeMouseListener(MouseListener l)
public void addMouseMotionListener(MouseMotionListener l) public void removeMouseMotionListener(MouseMotionListener l)
public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener ) public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )
public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener ) public synchronized void removeVetoableChangeListener(java.beans.VetoableChangeListener )