Interface ComponentFinder
- All Known Implementing Classes:
BasicComponentFinder
Component
lookup.-
Method Summary
Modifier and TypeMethodDescriptionfind
(Container root, ComponentMatcher m) Finds a
using the givenComponent
in the hierarchy under the given root.ComponentMatcher
<T extends Component>
Tfind
(Container root, GenericTypeMatcher<T> m) Finds a
using the givenComponent
in the hierarchy under the given root.GenericTypeMatcher
Finds a
using the givenComponent
.ComponentMatcher
<T extends Component>
Tfind
(GenericTypeMatcher<T> m) Finds a
using the givenComponent
.GenericTypeMatcher
findAll
(Container root, ComponentMatcher m) Returns all the
s under the given root that match the search criteria specified in the givenComponent
.ComponentMatcher
<T extends Component>
Collection<T>findAll
(Container root, GenericTypeMatcher<T> m) Returns all the
s under the given root that match the search criteria specified in the givenComponent
.GenericTypeMatcher
Returns all the
s that match the search criteria specified in the givenComponent
.ComponentMatcher
<T extends Component>
Collection<T>findAll
(GenericTypeMatcher<T> m) Returns all the
s that match the search criteria specified in the givenComponent
.GenericTypeMatcher
findByLabel
(Container root, String label) findByLabel
(Container root, String label, boolean showing) <T extends Component>
TfindByLabel
(Container root, String label, Class<T> type) <T extends Component>
TfindByLabel
(Container root, String label, Class<T> type, boolean showing) findByLabel
(String label) findByLabel
(String label, boolean showing) <T extends Component>
TfindByLabel
(String label, Class<T> type) <T extends Component>
TfindByLabel
(String label, Class<T> type, boolean showing) findByName
(Container root, String name) Finds a
by name, in the hierarchy under the given root.Component
findByName
(Container root, String name, boolean showing) Finds a
by name, in the hierarchy under the given root.Component
<T extends Component>
TfindByName
(Container root, String name, Class<T> type) Finds a
by name and type, in the hierarchy under the given root.Component
<T extends Component>
TfindByName
(Container root, String name, Class<T> type, boolean showing) Finds a
by name and type, in the hierarchy under the given root.Component
findByName
(String name) Finds a
by name.Component
findByName
(String name, boolean showing) Finds a
by name.Component
<T extends Component>
TfindByName
(String name, Class<T> type) Finds a
by name and type.Component
<T extends Component>
TfindByName
(String name, Class<T> type, boolean showing) Finds a
by name and type.Component
<T extends Component>
TfindByType
(Container root, Class<T> type) Finds a
by type in the hierarchy under the given root.Component
<T extends Component>
TfindByType
(Container root, Class<T> type, boolean showing) Finds a
by type in the hierarchy under the given root.Component
<T extends Component>
TfindByType
(Class<T> type) Finds a
by type.Component
<T extends Component>
TfindByType
(Class<T> type, boolean showing) Finds a
by type.Component
boolean
Returns whether the message in a
should include the current component hierarchy.ComponentLookupException
void
includeHierarchyIfComponentNotFound
(boolean newValue) Updates whether the message in a
should include the current component hierarchy.ComponentLookupException
printer()
Returns the
in this finder.ComponentPrinter
-
Method Details
-
printer
ComponentPrinter printer()Returns the
in this finder.ComponentPrinter
- Returns:
- the
ComponentPrinter
in this finder.
-
findByType
Finds a
by type. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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
Finds a
by type. For example:Component
- 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
Finds a
by type in the hierarchy under the given root. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.Let's assume we have the following
containing aJFrame
:JTextField
JFrame myFrame = new JFrame(); myFrame.add(new JTextField());
If we want to get a reference to the
in that particularJTextField
without going through the whole AWT component hierarchy, we could simply specify:JFrame
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
Finds a
by type in the hierarchy under the given root.Component
- 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
Finds a
by by the text of its associatedComponent
. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.Let's assume we have the
with aJTextField
with text "Name";JLabel
JLabel label = new JLabel("Name"); JTextField textbox = new JTextField(); label.setLabelFor(textBox);
To get a reference to this
by the text of its associatedJTextField
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:
- Parameters:
label
- the text of theJLabel
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
Finds a
by the text of its associatedComponent
and type. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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 theJLabel
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
- Type Parameters:
T
- the parameterized type of the component to find.- Parameters:
label
- the text of theJLabel
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
- Parameters:
label
- the text of theJLabel
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
Finds a
by the text of its associatedComponent
, in the hierarchy under the given root. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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 theJLabel
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
- Parameters:
root
- the root used as the starting point of the search.label
- the text of theJLabel
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
Finds a
by the text of its associatedComponent
and type, in the hierarchy under the given root. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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 theJLabel
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
Finds a
by the text of its associatedComponent
and type, in the hierarchy under the given root.JLabel
- 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 theJLabel
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
Finds a
by name. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.Let's assume we have the
with name "myTextBox";JTextField
JTextField textbox = new JTextField(); textBox.setName("myTextBox");
To get a reference to this
by its name, we can specify:JTextField
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:
- 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
Finds a
by name and type. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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
Finds a
by name and type.Component
- 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
Finds a
by name.Component
- 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
Finds a
by name, in the hierarchy under the given root. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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
Finds a
by name, in the hierarchy under the given root.Component
- 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
Finds a
by name and type, in the hierarchy under the given root. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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
Finds a
by name and type, in the hierarchy under the given root.Component
- 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
using the givenComponent
. The given matcher will be evaluated in the event dispatch thread. Implementations ofComponentMatcher
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
Finds a
using the givenComponent
. The given matcher will be evaluated in the event dispatch thread. Implementations ofGenericTypeMatcher
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
Finds a
using the givenComponent
in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations ofGenericTypeMatcher
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
using the givenComponent
in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations ofComponentMatcher
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
s that match the search criteria specified in the givenComponent
.ComponentMatcher
- Parameters:
m
- the matcher to use to find the component.- Returns:
- all the
Component
s that match the search criteria specified in the givenComponentMatcher
; or an empty collection, if there are no matching components.
-
findAll
Returns all the
s under the given root that match the search criteria specified in the givenComponent
.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
Component
s under the given root that match the search criteria specified in the givenComponentMatcher
; or an empty collection, if there are no matching components.
-
findAll
Returns all the
s that match the search criteria specified in the givenComponent
.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
Component
s that match the search criteria specified in the givenGenericTypeMatcher
; or an empty collection, if there are no matching components.
-
findAll
Returns all the
s under the given root that match the search criteria specified in the givenComponent
.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
Component
s under the given root that match the search criteria specified in the givenGenericTypeMatcher
; or an empty collection, if there are no matching components.
-
includeHierarchyIfComponentNotFound
boolean includeHierarchyIfComponentNotFound()Returns whether the message in a
should include the current component hierarchy. The default value isComponentLookupException
true
.- Returns:
true
if the component hierarchy is included as part of theComponentLookupException
message,false
otherwise.
-
includeHierarchyIfComponentNotFound
void includeHierarchyIfComponentNotFound(boolean newValue) Updates whether the message in a
should include the current component hierarchy. The default value isComponentLookupException
true
.- Parameters:
newValue
- the new value to set.
-