Interface ComponentFinder

All Known Implementing Classes:
BasicComponentFinder

@RunsInEDT public interface ComponentFinder
Understands GUI Component lookup.
  • Method Details

    • printer

      ComponentPrinter printer()
      Returns the ComponentPrinter in this finder.
      Returns:
      the ComponentPrinter in this finder.
    • findByType

      <T extends Component> T findByType(Class<T> type)
      Finds a Component by type. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

      Example:

       JTextField textbox = finder.findByType(JTextField.class);
       

      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByType

      <T extends Component> T findByType(Class<T> type, boolean showing)
      Finds a Component by type. For example:
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      type - the type of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByType

      <T extends Component> T findByType(Container root, Class<T> type)

      Finds a Component by type in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

      Let's assume we have the following JFrame containing a JTextField:

       JFrame myFrame = new JFrame();
       myFrame.add(new JTextField());
       

      If we want to get a reference to the JTextField in that particular JFrame without going through the whole AWT component hierarchy, we could simply specify:

       JTextField textbox = finder.findByType(myFrame, JTextField.class);
       

      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      root - the root used as the starting point of the search.
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByType

      <T extends Component> T findByType(Container root, Class<T> type, boolean showing)
      Finds a Component by type in the hierarchy under the given root.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      root - the root used as the starting point of the search.
      showing - indicates whether the component to find should be visible (or showing) or not.
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      Component findByLabel(String label)

      Finds a Component by by the text of its associated JLabel. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

      Let's assume we have the JTextField with a JLabel with text "Name";

       JLabel label = new JLabel("Name");
       JTextField textbox = new JTextField();
       label.setLabelFor(textBox);
       

      To get a reference to this JTextField by the text of its associated JLabel, we can specify:

       JTextField textBox = (JTextField) finder.findByLabel("Name");
       

      Please note that you need to cast the result of the lookup to the right type. To avoid casting, please use one of following:

      1. findByLabel(String, Class)
      2. findByLabel(String, Class, boolean)
      3. findByLabel(Container, String, Class)
      4. findByLabel(Container, String, Class, boolean)

      Parameters:
      label - the text of the JLabel associated to the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      <T extends Component> T findByLabel(String label, Class<T> type)
      Finds a Component by the text of its associated JLabel and type. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      label - the text of the JLabel associated to the component to find.
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      <T extends Component> T findByLabel(String label, Class<T> type, boolean showing)
      Finds a Component by the text of its associated JLabel and type.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      label - the text of the JLabel associated to the component to find.
      type - the type of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      Component findByLabel(String label, boolean showing)
      Finds a Component by by the text of its associated JLabel.
      Parameters:
      label - the text of the JLabel associated to the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      Component findByLabel(Container root, String label)
      Finds a Component by the text of its associated JLabel, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.
      Parameters:
      root - the root used as the starting point of the search.
      label - the text of the JLabel associated to the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      Component findByLabel(Container root, String label, boolean showing)
      Finds a Component by the text of its associated JLabel, in the hierarchy under the given root.
      Parameters:
      root - the root used as the starting point of the search.
      label - the text of the JLabel associated to the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      <T extends Component> T findByLabel(Container root, String label, Class<T> type)
      Finds a Component by the text of its associated JLabel and type, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      root - the root used as the starting point of the search.
      label - the text of the JLabel associated to the component to find.
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByLabel

      <T extends Component> T findByLabel(Container root, String label, Class<T> type, boolean showing)
      Finds a Component by the text of its associated JLabel and type, in the hierarchy under the given root.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      root - the root used as the starting point of the search.
      label - the text of the JLabel associated to the component to find.
      type - the type of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      Component findByName(String name)

      Finds a Component by name. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

      Let's assume we have the JTextField with name "myTextBox";

       JTextField textbox = new JTextField();
       textBox.setName("myTextBox");
       

      To get a reference to this JTextField by its name, we can specify:

       JTextField textBox = (JTextField) finder.findByName("myTextBox");
       

      Please note that you need to cast the result of the lookup to the right type. To avoid casting, please use one of following:

      1. findByName(String, Class)
      2. findByName(String, Class, boolean)
      3. findByName(Container, String, Class)
      4. findByName(Container, String, Class, boolean)

      Parameters:
      name - the name of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      <T extends Component> T findByName(String name, Class<T> type)
      Finds a Component by name and type. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      name - the name of the component to find.
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      <T extends Component> T findByName(String name, Class<T> type, boolean showing)
      Finds a Component by name and type.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      name - the name of the component to find.
      type - the type of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      Component findByName(String name, boolean showing)
      Finds a Component by name.
      Parameters:
      name - the name of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      Component findByName(Container root, String name)
      Finds a Component by name, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.
      Parameters:
      root - the root used as the starting point of the search.
      name - the name of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      Component findByName(Container root, String name, boolean showing)
      Finds a Component by name, in the hierarchy under the given root.
      Parameters:
      root - the root used as the starting point of the search.
      name - the name of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      <T extends Component> T findByName(Container root, String name, Class<T> type)
      Finds a Component by name and type, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      root - the root used as the starting point of the search.
      name - the name of the component to find.
      type - the type of the component to find.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • findByName

      <T extends Component> T findByName(Container root, String name, Class<T> type, boolean showing)
      Finds a Component by name and type, in the hierarchy under the given root.
      Type Parameters:
      T - the parameterized type of the component to find.
      Parameters:
      root - the root used as the starting point of the search.
      name - the name of the component to find.
      type - the type of the component to find.
      showing - indicates whether the component to find should be visible (or showing) or not.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
      See Also:
    • find

      Finds a Component using the given ComponentMatcher. The given matcher will be evaluated in the event dispatch thread. Implementations of ComponentMatcher do not need to be concerned about the event dispatch thread.
      Parameters:
      m - the matcher to use to find the component of interest.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
    • find

      <T extends Component> T find(GenericTypeMatcher<T> m)
      Finds a Component using the given GenericTypeMatcher. The given matcher will be evaluated in the event dispatch thread. Implementations of GenericTypeMatcher do not need to be concerned about the event dispatch thread.
      Type Parameters:
      T - the type of component the given matcher can handle.
      Parameters:
      m - the matcher to use to find the component of interest.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
    • find

      <T extends Component> T find(Container root, GenericTypeMatcher<T> m)
      Finds a Component using the given GenericTypeMatcher in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations of GenericTypeMatcher do not need to be concerned about the event dispatch thread.
      Type Parameters:
      T - the type of component the given matcher can handle.
      Parameters:
      root - the root used as the starting point of the search.
      m - the matcher to use to find the component.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
    • find

      Finds a Component using the given ComponentMatcher in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations of ComponentMatcher do not need to be concerned about the event dispatch thread.
      Parameters:
      root - the root used as the starting point of the search.
      m - the matcher to use to find the component.
      Returns:
      the found component.
      Throws:
      ComponentLookupException - if a matching component could not be found.
      ComponentLookupException - if more than one matching component is found.
    • findAll

      Returns all the Components that match the search criteria specified in the given ComponentMatcher.
      Parameters:
      m - the matcher to use to find the component.
      Returns:
      all the Components that match the search criteria specified in the given ComponentMatcher; or an empty collection, if there are no matching components.
    • findAll

      Returns all the Components under the given root that match the search criteria specified in the given ComponentMatcher.
      Parameters:
      root - the root used as the starting point of the search.
      m - the matcher to use to find the component.
      Returns:
      all the Components under the given root that match the search criteria specified in the given ComponentMatcher; or an empty collection, if there are no matching components.
    • findAll

      <T extends Component> Collection<T> findAll(GenericTypeMatcher<T> m)
      Returns all the Components that match the search criteria specified in the given GenericTypeMatcher.
      Type Parameters:
      T - the generic type of component that this search supports.
      Parameters:
      m - the matcher to use to find the component.
      Returns:
      all the Components that match the search criteria specified in the given GenericTypeMatcher; or an empty collection, if there are no matching components.
    • findAll

      <T extends Component> Collection<T> findAll(Container root, GenericTypeMatcher<T> m)
      Returns all the Components under the given root that match the search criteria specified in the given GenericTypeMatcher.
      Type Parameters:
      T - the generic type of component that this search supports.
      Parameters:
      root - the root used as the starting point of the search.
      m - the matcher to use to find the component.
      Returns:
      all the Components under the given root that match the search criteria specified in the given GenericTypeMatcher; or an empty collection, if there are no matching components.
    • includeHierarchyIfComponentNotFound

      boolean includeHierarchyIfComponentNotFound()
      Returns whether the message in a ComponentLookupException should include the current component hierarchy. The default value is true.
      Returns:
      true if the component hierarchy is included as part of the ComponentLookupException message, false otherwise.
    • includeHierarchyIfComponentNotFound

      void includeHierarchyIfComponentNotFound(boolean newValue)
      Updates whether the message in a ComponentLookupException should include the current component hierarchy. The default value is true.
      Parameters:
      newValue - the new value to set.