Class JButtonMatcher

All Implemented Interfaces:
ComponentMatcher, ResettableComponentMatcher

public final class JButtonMatcher extends NamedComponentMatcherTemplate<JButton>
Understands matching a JButton by name, text and visibility on the screen.
  • Field Details

  • Constructor Details

    • JButtonMatcher

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

    • withName

      public static JButtonMatcher withName(String name)
      Creates a new JButtonMatcher that matches a JButton 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 JButton by name and text:

         JButtonMatcher m = withName("ok").andText("OK");
         

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

         JButtonMatcher m = withName("ok").andText("OK").andShowing();
         

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

      public static JButtonMatcher withText(String text)
      Creates a new JButtonMatcher that matches a JButton by its text.

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

       JButtonMatcher m = withText("OK");
       

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

       JButtonMatcher m = withText("OK").andShowing();
       

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

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

      The following code listing shows how to match a JButton by text, using a regular expression pattern:

       JButtonMatcher m = withText(Pattern.compile("O.*"));
       

      The following code listing shows how to match a JButton, that should be showing on the screen, by text, using a regular expression pattern:

       JButtonMatcher m = withText(Pattern.compile("O.*")).andShowing();
       

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

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

      public JButtonMatcher 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 JButtonMatcher 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 JButtonMatcher andShowing()
      Indicates that the JButton to match should be showing on the screen.
      Returns:
      this matcher.
    • isMatching

      @RunsInCurrentThread protected boolean isMatching(JButton button)
      Indicates whether:
      • the name of the given JButton is equal to the name in this matcher, and
      • the text of the given JButton matches the text (or pattern) 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<JButton>
      Parameters:
      button - the JButton to match.
      Returns:
      true if the JButton matches the search criteria in this matcher.
    • toString

      public String toString()
      Overrides:
      toString in class Object