@RunsInEDT public interface ComponentFinder
Component
s based on different search criteria, such as a Component
's name,
type or label, and custom search criteria as well.Modifier and Type | Method and Description |
---|---|
Component |
find(ComponentMatcher m)
Finds an AWT or Swing
Component using the given ComponentMatcher . |
Component |
find(Container root,
ComponentMatcher m)
Finds an AWT or Swing
Component using the given ComponentMatcher in the hierarchy under the given
root. |
<T extends Component> |
find(Container root,
GenericTypeMatcher<T> m)
Finds an AWT or Swing
Component using the given GenericTypeMatcher in the hierarchy under the given
root. |
<T extends Component> |
find(GenericTypeMatcher<T> m)
Finds an AWT or Swing
Component using the given GenericTypeMatcher . |
Collection<Component> |
findAll(ComponentMatcher m)
Returns all the AWT or Swing
Component s that match the search criteria specified in the given
ComponentMatcher . |
Collection<Component> |
findAll(Container root,
ComponentMatcher m)
Returns all the AWT or Swing
Component s under the given root that match the search criteria specified in
the given ComponentMatcher . |
<T extends Component> |
findAll(Container root,
GenericTypeMatcher<T> m)
Returns all the AWT or Swing
Component s under the given root that match the search criteria specified in
the given GenericTypeMatcher . |
<T extends Component> |
findAll(GenericTypeMatcher<T> m)
Returns all the AWT or Swing
Component s that match the search criteria specified in the given
GenericTypeMatcher . |
Component |
findByLabel(Container root,
String label)
Finds an AWT or Swing
Component by the text of its associated JLabel , in the hierarchy under the
given root. |
Component |
findByLabel(Container root,
String label,
boolean showing)
Finds an AWT or Swing
Component by the text of its associated JLabel , in the hierarchy under the
given root. |
<T extends Component> |
findByLabel(Container root,
String label,
Class<T> type)
Finds an AWT or Swing
Component by the text of its associated JLabel and type, in the hierarchy
under the given root. |
<T extends Component> |
findByLabel(Container root,
String label,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by the text of its associated JLabel and type, in the hierarchy
under the given root. |
Component |
findByLabel(String label)
Finds an AWT or Swing
Component by by the text of its associated JLabel . |
Component |
findByLabel(String label,
boolean showing)
Finds an AWT or Swing
Component by by the text of its associated JLabel . |
<T extends Component> |
findByLabel(String label,
Class<T> type)
Finds an AWT or Swing
Component by the text of its associated JLabel and type. |
<T extends Component> |
findByLabel(String label,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by the text of its associated JLabel and type. |
Component |
findByName(Container root,
String name)
Finds an AWT or Swing
Component by name, in the hierarchy under the given root. |
Component |
findByName(Container root,
String name,
boolean showing)
Finds an AWT or Swing
Component by name, in the hierarchy under the given root. |
<T extends Component> |
findByName(Container root,
String name,
Class<T> type)
Finds an AWT or Swing
Component by name and type, in the hierarchy under the given root. |
<T extends Component> |
findByName(Container root,
String name,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by name and type, in the hierarchy under the given root. |
Component |
findByName(String name)
Finds an AWT or Swing
Component by name. |
Component |
findByName(String name,
boolean showing)
Finds an AWT or Swing
Component by name. |
<T extends Component> |
findByName(String name,
Class<T> type)
Finds an AWT or Swing
Component by name and type. |
<T extends Component> |
findByName(String name,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by name and type. |
<T extends Component> |
findByType(Class<T> type)
Finds an AWT or Swing
Component by type. |
<T extends Component> |
findByType(Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by type. |
<T extends Component> |
findByType(Container root,
Class<T> type)
Finds an AWT or Swing
Component by type in the hierarchy under the given root. |
<T extends Component> |
findByType(Container root,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by type in the hierarchy under the given root. |
boolean |
includeHierarchyIfComponentNotFound()
Returns whether the message in a
ComponentLookupException should include the
current component hierarchy. |
void |
includeHierarchyIfComponentNotFound(boolean newValue)
Updates whether the message in a
ComponentLookupException should include the
current component hierarchy. |
ComponentPrinter |
printer() |
@Nonnull ComponentPrinter printer()
ComponentPrinter
in this finder.@Nonnull <T extends Component> T findByType(@Nonnull Class<T> type)
Finds an AWT or Swing 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);
T
- the type of the component to find.type
- the class of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull <T extends Component> T findByType(@Nonnull Class<T> type, boolean showing)
Component
by type. For example:T
- the type of the component to find.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByType(Class)
@Nonnull <T extends Component> T findByType(@Nonnull Container root, @Nonnull Class<T> type)
Finds an AWT or Swing 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);
T
- the type of the component to find.root
- the root used as the starting point of the search.type
- the class of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull <T extends Component> T findByType(@Nonnull Container root, @Nonnull Class<T> type, boolean showing)
Component
by type in the hierarchy under the given root.T
- the type of the component to find.root
- the root used as the starting point of the search.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByType(Container, Class)
@Nonnull Component findByLabel(@Nullable String label)
Finds an AWT or Swing 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:
label
- the text of the JLabel
associated to the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
,
Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull <T extends Component> T findByLabel(@Nullable String label, @Nonnull Class<T> type)
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.T
- the type of the component to find.label
- the text of the JLabel
associated to the component to find.type
- the class of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
,
Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull <T extends Component> T findByLabel(@Nullable String label, @Nonnull Class<T> type, boolean showing)
Component
by the text of its associated JLabel
and type.T
- the type of the component to find.label
- the text of the JLabel
associated to the component to find.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
@Nonnull Component findByLabel(@Nullable String label, boolean showing)
Component
by by the text of its associated JLabel
.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.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
@Nonnull Component findByLabel(@Nonnull Container root, @Nullable String label)
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.root
- the root used as the starting point of the search.label
- the text of the JLabel
associated to the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
,
Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull Component findByLabel(@Nonnull Container root, @Nullable String label, boolean showing)
Component
by the text of its associated JLabel
, in the hierarchy under the
given root.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.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
@Nonnull <T extends Component> T findByLabel(@Nonnull Container root, @Nullable String label, @Nonnull Class<T> type)
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.T
- the type of the component to find.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 class of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
,
Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull <T extends Component> T findByLabel(@Nonnull Container root, @Nullable String label, @Nonnull Class<T> type, boolean showing)
Component
by the text of its associated JLabel
and type, in the hierarchy
under the given root.T
- the type of the component to find.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 class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
@Nonnull Component findByName(@Nullable String name)
Finds an AWT or Swing 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:
name
- the name of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@Nonnull <T extends Component> T findByName(@Nullable String name, @Nonnull Class<T> type)
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.T
- the type of the component to find.name
- the name of the component to find.type
- the class of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
,
findByName(String)
@Nonnull <T extends Component> T findByName(@Nullable String name, @Nonnull Class<T> type, boolean showing)
Component
by name and type.T
- the type of the component to find.name
- the name of the component to find.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByName(String)
@Nonnull Component findByName(@Nullable String name, boolean showing)
Component
by name.name
- the name of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByName(String)
@Nonnull Component findByName(@Nonnull Container root, @Nullable String name)
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.root
- the root used as the starting point of the search.name
- the name of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
,
findByName(String)
@Nonnull Component findByName(@Nonnull Container root, @Nullable String name, boolean showing)
Component
by name, in the hierarchy under the given root.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.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByName(String)
@Nonnull <T extends Component> T findByName(@Nonnull Container root, @Nullable String name, @Nonnull Class<T> type)
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.T
- the type of the component to find.root
- the root used as the starting point of the search.name
- the name of the component to find.type
- the class of the component to find.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
,
findByName(String)
@Nonnull <T extends Component> T findByName(@Nonnull Container root, @Nullable String name, @Nonnull Class<T> type, boolean showing)
Component
by name and type, in the hierarchy under the given root.T
- the type of the component to find.root
- the root used as the starting point of the search.name
- the name of the component to find.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.findByName(String)
@Nonnull Component find(@Nonnull ComponentMatcher m)
Component
using the given ComponentMatcher
. The given matcher will be
evaluated in the event dispatch thread (EDT). Implementations of ComponentMatcher
do not need to be
concerned about the event dispatch thread (EDT).m
- the matcher to use to find the component of interest.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.@Nonnull <T extends Component> T find(@Nonnull GenericTypeMatcher<T> m)
Component
using the given GenericTypeMatcher
. The given matcher will be
evaluated in the event dispatch thread (EDT). Implementations of GenericTypeMatcher
do not need to be
concerned about the event dispatch thread (EDT).T
- the type of the component to find.m
- the matcher to use to find the component of interest.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.@Nonnull <T extends Component> T find(@Nonnull Container root, @Nonnull GenericTypeMatcher<T> m)
Component
using the given GenericTypeMatcher
in the hierarchy under the given
root. The given matcher will be evaluated in the event dispatch thread (EDT). Implementations of
GenericTypeMatcher
do not need to be concerned about the event dispatch thread (EDT).T
- the type of the component to find.root
- the root used as the starting point of the search.m
- the matcher to use to find the component.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.@Nonnull Component find(@Nullable Container root, @Nonnull ComponentMatcher m)
Component
using the given ComponentMatcher
in the hierarchy under the given
root. The given matcher will be evaluated in the event dispatch thread (EDT). Implementations of
ComponentMatcher
do not need to be concerned about the event dispatch thread (EDT).root
- the root used as the starting point of the search.m
- the matcher to use to find the component.ComponentLookupException
- if a matching component could not be found.ComponentLookupException
- if more than one matching component is found.@Nonnull Collection<Component> findAll(@Nonnull ComponentMatcher m)
Component
s that match the search criteria specified in the given
ComponentMatcher
.m
- the matcher to use to find the component.Component
s that match the search criteria specified in the given ComponentMatcher
;
or an empty collection, if there are no matching components.@Nonnull Collection<Component> findAll(@Nonnull Container root, @Nonnull ComponentMatcher m)
Component
s under the given root that match the search criteria specified in
the given ComponentMatcher
.root
- the root used as the starting point of the search.m
- the matcher to use to find the component.Component
s under the given root that match the search criteria specified in the given
ComponentMatcher
; or an empty collection, if there are no matching components.@Nonnull <T extends Component> Collection<T> findAll(@Nonnull GenericTypeMatcher<T> m)
Component
s that match the search criteria specified in the given
GenericTypeMatcher
.T
- the type of the component to find.m
- the matcher to use to find the component.Component
s that match the search criteria specified in the given GenericTypeMatcher
; or an empty collection, if there are no matching components.@Nonnull <T extends Component> Collection<T> findAll(@Nonnull Container root, @Nonnull GenericTypeMatcher<T> m)
Component
s under the given root that match the search criteria specified in
the given GenericTypeMatcher
.T
- the type of the component to find.root
- the root used as the starting point of the search.m
- the matcher to use to find the component.Component
s under the given root that match the search criteria specified in the given
GenericTypeMatcher
; or an empty collection, if there are no matching components.boolean includeHierarchyIfComponentNotFound()
ComponentLookupException
should include the
current component hierarchy.
The default value is true
.true
if the component hierarchy is included as part of the
org.assertj.swing.exception.ComponentLookupException
message, false
otherwise.void includeHierarchyIfComponentNotFound(boolean newValue)
ComponentLookupException
should include the
current component hierarchy.
The default value is true
.newValue
- the new value to set.Copyright © 2014–2019 AssertJ. All rights reserved.