Class VerticalButtonNavigator

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class VerticalButtonNavigator extends JPanel
VerticalButtonList is a component that displays a column of toggle buttons. It can be easily used in PJF AppCenter Navigator to switch between different screens in the workarea.

VerticalButtonList API is very similar to javax.swing.JList. It uses the same ListModel as JList does, fires ListSelectionEvent when a button is pressed, etc.

To use it, create a javax.swing.ListModel containing the String names for the buttons that are displayed. Instantiate VerticalButtonNavigator passing it the model. Create and register a ListSelectionListener that will receive ListSelectionEvents when a button is pressed.

Alternatively, the button names can be passed in either as an Object array or a Vector. For example

 VerticalButtonNavigator mVBL;
 String[] btns = {
    "Btn 1\nSecond Line", "Btn 2", "Btn 3"};

 mVBL = new VerticalButtonNavigator(btns);
 mVBL.setSelectedValue("Btn 2");

 mVBL.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
        // handle button selection here
        System.out.println(e); 
    }
 });

 

Author:
Max Spivak
See Also:
  • Constructor Details

    • VerticalButtonNavigator

      public VerticalButtonNavigator(ListModel listModel)
      Create a VerticalButtonNavigator from a list model. The list model may not be null and should contain string labels that will appear on the buttons.
      Parameters:
      listModel - non-null javax.swing.ListModel that contains the strings that will be used as button labels
    • VerticalButtonNavigator

      public VerticalButtonNavigator(Object[] listData)
      Create VerticalButtonNavigator passing in an Object array. Each element should be a String.
      Parameters:
      listData - Array of strings that are used as button labels.
    • VerticalButtonNavigator

      public VerticalButtonNavigator(Vector listData)
      Create VerticalButtonNavigator passing in a Vector. Each vector element should be a String.
      Parameters:
      listData - Vector of Strings that are used as button labels.
    • VerticalButtonNavigator

      public VerticalButtonNavigator()
      Create a VerticalButtonNavigator with no elements. Not very useful; included here for API completeness.
  • Method Details

    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • setModel

      public void setModel(ListModel model)
    • addListSelectionListener

      public void addListSelectionListener(ListSelectionListener listener)
      Add a ListSelectionListener to this component. When a button is selected a ListSelectionEvent is fired (just as in a JList).
    • removeListSelectionListener

      public void removeListSelectionListener(ListSelectionListener listener)
      Remove a previously-added ListSelectionListener from this component.
    • fireListSelectionListenerValueChanged

      protected void fireListSelectionListenerValueChanged()
      Iterates through ListSelectionListeners and fires ListSelectionEvent.
    • setValueEnabled

      public void setValueEnabled(String buttonLabel, boolean enabled)
      Sets the button specified by label to be enabled or disabled
      Parameters:
      buttonLabel - The button label to set
      enabled - Whether to enable or disable the button
    • setSelectedValue

      public void setSelectedValue(String buttonLabel)
      Selects the button with specified value.
      Parameters:
      buttonLabel - The label of the button to select
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Select button based on its zero-based index.
      Parameters:
      index - Index of button to select. Ensure that index is within bounds.
    • getSelectedIndex

      public int getSelectedIndex()
    • getSelectedValue

      public Object getSelectedValue()
      Returns the selected value. The return value will be a button label String or null if nothing is selected.
      Returns:
      String of selected button or null if nothing is selected