Class JLabelMatcher

All Implemented Interfaces:
ComponentMatcher, ResettableComponentMatcher

public final class JLabelMatcher extends NamedComponentMatcherTemplate<JLabel>
Understands matching a JLabel by type, name or text.
  • Field Details

  • Constructor Details

    • JLabelMatcher

      private JLabelMatcher(Object name, Object text)
  • Method Details

    • withName

      public static JLabelMatcher withName(String name)
      Creates a new JLabelMatcher that matches a JLabel that:
      1. has a matching name
      2. (optionally) has matching text
      3. (optionally) is showing on the screen
      4. The following code listing shows how to match a JLabel by name and text:

         JLabelMatcher m = withName("firstName").andText("First Name:");
         

        The following code listing shows how to match a JLabel, that should be showing on the screen, by name and text:

         JLabelMatcher m = withName("firstName").andText("First Name:").andShowing();
         

      Parameters:
      name - the id to match.
      Returns:
      the created matcher.
    • withText

      public static JLabelMatcher withText(String text)
      Creates a new JLabelMatcher that matches a JLabel by its text.

      The following code listing shows how to match a JLabel by text:

       JLabelMatcher m = withText("First Name:");
       

      The following code listing shows how to match a JLabel, that should be showing on the screen, by text:

       JLabelMatcher m = withText("First Name:").andShowing();
       

      Parameters:
      text - the text to match. It can be a regular expression.
      Returns:
      the created matcher.
    • withText

      public static JLabelMatcher withText(Pattern textPattern)
      Creates a new JLabelMatcher that matches a JLabel by its text.

      The following code listing shows how to match a JLabel by text:

       JLabelMatcher m = withText(Pattern.compile("F.*");
       

      The following code listing shows how to match a JLabel, that should be showing on the screen, by text:

       JLabelMatcher m = withText(Pattern.compile("F.*").andShowing();
       

      Parameters:
      textPattern - the regular expression pattern to match.
      Returns:
      the created matcher.
      Since:
      1.2
    • any

      public static JLabelMatcher any()
      Creates a new JLabelMatcher that matches any JLabel.
      Returns:
      the created matcher.
    • andText

      public JLabelMatcher andText(String newText)
      Specifies the text to match. If this matcher was created using withText(String) or withText(Pattern), this method will simply update the text to match.
      Parameters:
      newText - the new text to match. It can be a regular expression.
      Returns:
      this matcher.
    • andText

      public JLabelMatcher andText(Pattern textPattern)
      Specifies the text to match. If this matcher was created using withText(String) or withText(Pattern), this method will simply update the text to match.
      Parameters:
      textPattern - the regular expression pattern to match.
      Returns:
      this matcher.
      Since:
      1.2
    • andShowing

      public JLabelMatcher andShowing()
      Indicates that the JLabel to match should be showing on the screen.
      Returns:
      this matcher.
    • isMatching

      @RunsInCurrentThread protected boolean isMatching(JLabel button)
      Indicates whether the text of the given JLabel is equal to the text 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.

      Specified by:
      isMatching in class GenericTypeMatcher<JLabel>
      Parameters:
      button - the JLabel to match.
      Returns:
      true if the text in the JLabel is equal to the text in this matcher, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object