borland Packages  Class Hierarchy  jbcl.control Package  Index 

ButtonBar component

java.lang.Object
   +----java.awt.Component
           +----java.awt.Container
                   +----com.sun.java.swing.JComponent
                           +----borland.jbcl.view.BeanPanel
                                   +----borland.jbcl.control.BevelPanel
                                           +----borland.jbcl.control.ButtonBar
                                                   +----borland.jbcl.control.NavigatorControl

About the ButtonBar component

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 Working with Advanced Components in the Building Applications with JBuilder and Step 12 of the tutorial Building a Java Text Editor in the Quick Start.

Example

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 borland.jbcl.control.*;
import 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(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);
  }
}


ButtonBar variables

Variables implemented in this class

Variables implemented in borland.jbcl.control.BevelPanel

Variables implemented in borland.jbcl.view.BeanPanel

Variables implemented in com.sun.java.swing.JComponent

Variables implemented in java.awt.Component

ButtonBar constructors

ButtonBar properties

*Read-only properties **Write-only properties

Properties implemented in this class

Properties implemented in borland.jbcl.control.BevelPanel

Properties implemented in borland.jbcl.view.BeanPanel

Properties implemented in com.sun.java.swing.JComponent

Properties implemented in java.awt.Component

Properties implemented in java.awt.Container

Properties implemented in java.lang.Object

ButtonBar methods

Methods implemented in this class

Methods implemented in borland.jbcl.control.BevelPanel

Methods implemented in borland.jbcl.view.BeanPanel

Methods implemented in com.sun.java.swing.JComponent

Methods implemented in java.awt.Component

Methods implemented in java.awt.Container

Methods implemented in java.lang.Object

ButtonBar event listeners


ButtonBar variables

actionMulticaster

  protected transient ActionMulticaster actionMulticaster

border

  protected BorderItemPainter border

IMAGE_ONLY

  public static final int IMAGE_ONLY = 2
A buttonType constant for buttons displaying (only) images.

mouseMotionMulticaster

  protected transient MouseMotionMulticaster mouseMotionMulticaster

mouseMulticaster

  protected transient MouseMulticaster mouseMulticaster

needsRebuild

  protected boolean needsRebuild

TEXT_AND_IMAGE

  public static final int TEXT_AND_IMAGE = 3
A buttonType constant for buttons that display both text and an image.

TEXT_ONLY

  public static final int TEXT_ONLY = 1
A buttonType constant for buttons that display text only.

ButtonBar constructors

ButtonBar()

  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.


ButtonBar properties

alignment

 public int getAlignment()
 public void setAlignment(int alignment)
Stores the alignment for this ButtonBar. Accepted values for alignment are defined in Alignment variables.

buttonAlignment

 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.

buttonOrientation

 public int getButtonOrientation()
 public void setButtonOrientation(int o)
Stores how the label and image are oriented. Valid values are Orientation.HORIZONTAL or Orientation.VERTICAL. Buttons are added to the ButtonBar from left to right for a horizontal ButtonBar or top down for a vertical ButtonBar.

buttonType

 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.

enabled

 public void setEnabled(boolean enabled)
Write-only property that enables or disables the ButtonBar.

hgap

 public int getHgap()
 public void setHgap(int gap)
Specifies the horizontal gap setting for this ButtonBar, in pixels.

imageBase

 public String getImageBase()
 public void setImageBase(java.lang.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.

imageFirst

 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

imageNames

 public String[] getImageNames()
 public void setImageNames(java.lang.String[] imageNames)
Specifies the array of String names for the images displayed on the ButtonBar.

labels

 public String[] getLabels()
 public void setLabels(java.lang.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.

opaque

 public void setOpaque(boolean opaque)
Write-only property that determines whether the ButtonBar is opaque or not.

preferredSize

 public Dimension getPreferredSize()
Stores the preferred dimensions to use when drawing the ButtonBar.

showRollover

 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.

vgap

 public int getVgap()
 public void setVgap(int gap)
Stores the vertical gap setting, in pixels, for this ButtonBar.


ButtonBar methods

addImageButton(java.awt.Image, java.lang.String, java.lang.String)

  protected Component addImageButton(java.awt.Image image, java.lang.String label, java.lang.String command)
Creates a new ImageButton with the properties specified in its parameters and adds it to the ButtonBar.

Parameters:

image
The image on the button.
label
The string label on the button.
command
The actionId associated with this button by which you can later refer to this button.

addSpace()

  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).

addSpace(int)

  protected Component addSpace(int gap)
Adds the specified amount of space (in pixels) between each button then repaints the ButtonBar.

addTextButton(java.lang.String, java.lang.String)

  protected Component addTextButton(java.lang.String label, java.lang.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
The text that appears on the button.
command
The actionId associated with this button by which you can later refer to this button.

assureImages()

  protected void assureImages()

doLayout()

  public void doLayout()

Overrides: java.awt.Container.doLayout()

invalidateButtons()

  protected void invalidateButtons()

invalidateImages()

  protected void invalidateImages()

isButtonEnabled(int)

  public boolean isButtonEnabled(int index)
Returns whether the button at the specified position index is enabled or not.

isButtonEnabled(java.lang.String)

  public boolean isButtonEnabled(java.lang.String label)
Returns whether the button with the specified label is enabled or not.

isButtonVisible(int)

  public boolean isButtonVisible(int index)
Returns whether the button at the specified position index is visible or not.

isButtonVisible(java.lang.String)

  public boolean isButtonVisible(java.lang.String label)
Returns whether the button with the specified label is visible or not.

rebuild()

  protected void rebuild()
Rebuilds the ButtonBar.

setButtonEnabled(int, boolean)

  public void setButtonEnabled(int index, boolean enabled)
Enables or disables a particular button by index.

Parameters:

index
The index position of the button to be affected.
enabled
Whether or not to enable the button.

setButtonEnabled(java.lang.String, boolean)

  public void setButtonEnabled(java.lang.String label, boolean enabled)
Enables or disables a particular button by label.

Parameters:

label
The label of the button to be affected.
enabled
Whether or not to enable the button.

setButtonVisible(int, boolean)

  public void setButtonVisible(int index, boolean visible)
Sets a particular button to visible or invisible by index

Parameters:

index
The index of the button to be affected.
visible
Whether or not to make the button visible.

setButtonVisible(java.lang.String, boolean)

  public void setButtonVisible(java.lang.String label, boolean visible)
Sets a particular button to visible or invisible by label

Parameters:

label
The label of the button to be affected.
visible
Whether or not to make the button visible.

ButtonBar event listeners

This component is a source for the following event sets. For information on the standard AWT event sets, see Standard Java events.

action

 public synchronized void addActionListener(java.awt.event.ActionListener l)
 public synchronized void removeActionListener(java.awt.event.ActionListener l)

ancestor

 public void addAncestorListener(com.sun.java.swing.event.AncestorListener )
 public void removeAncestorListener(com.sun.java.swing.event.AncestorListener )

component

 public synchronized void addComponentListener(java.awt.event.ComponentListener )
 public synchronized void removeComponentListener(java.awt.event.ComponentListener )

container

 public synchronized void addContainerListener(java.awt.event.ContainerListener )
 public void removeContainerListener(java.awt.event.ContainerListener )

focus

 public synchronized void addFocusListener(java.awt.event.FocusListener )
 public synchronized void removeFocusListener(java.awt.event.FocusListener )

key

 public synchronized void addKeyListener(java.awt.event.KeyListener )
 public synchronized void removeKeyListener(java.awt.event.KeyListener )

mouse

 public void addMouseListener(java.awt.event.MouseListener l)
 public void removeMouseListener(java.awt.event.MouseListener l)

mouseMotion

 public void addMouseMotionListener(java.awt.event.MouseMotionListener l)
 public void removeMouseMotionListener(java.awt.event.MouseMotionListener l)

propertyChange

 public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener )
 public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )

vetoableChange

 public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener )
 public synchronized void removeVetoableChangeListener(java.beans.VetoableChangeListener )