Class LabelMatcher

All Implemented Interfaces:
ComponentMatcher, ResettableComponentMatcher

public class LabelMatcher extends AbstractComponentMatcher
Understands Component matching by the text of the associated JLabel and (optionally) by type.
See Also:
  • Field Details

  • Constructor Details

    • LabelMatcher

      public LabelMatcher(String label)
      Creates a new LabelMatcher. The component to match does not have to be showing.
      Parameters:
      label - the text of the label associated to the component we are looking for.
      Throws:
      NullPointerException - if the given label is null.
      IllegalArgumentException - if the given label is empty.
    • LabelMatcher

      public LabelMatcher(String label, boolean requireShowing)
      Creates a new LabelMatcher.
      Parameters:
      label - the text of the label associated to the component we are looking for.
      requireShowing - indicates if the component to match should be showing or not.
      Throws:
      NullPointerException - if the given label is null.
      IllegalArgumentException - if the given label is empty.
    • LabelMatcher

      public LabelMatcher(String label, Class<? extends Component> type)
      Creates a new LabelMatcher. The component to match does not have to be showing.
      Parameters:
      label - the text of the label associated to the component we are looking for.
      type - the type of the component we are looking for.
      Throws:
      NullPointerException - if the given label is null.
      IllegalArgumentException - if the given label is empty.
      NullPointerException - if the given type is null.
    • LabelMatcher

      public LabelMatcher(String label, Class<? extends Component> type, boolean requireShowing)
      Creates a new LabelMatcher.
      Parameters:
      label - the text of the label associated to the component we are looking for.
      type - the type of the component we are looking for.
      requireShowing - indicates if the component to match should be showing or not.
      Throws:
      NullPointerException - if the given label is null.
      IllegalArgumentException - if the given label is empty.
      NullPointerException - if the given type is null.
  • Method Details

    • matches

      @RunsInCurrentThread public boolean matches(Component c)
      Indicates whether the given Component matches the criteria specified in this matcher:
      1. the text of the JLabel
      2. attached to the component to look for matches the text specified in this matcher
      3. the component to look for is of the type specified in this matcher (if specified)
      4. visibility of the given Component matches the value specified in this matcher

      Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Parameters:
      c - the Component to verify.
      Returns:
      true if the name and visibility of the given Component matches the values specified in this matcher, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object