public class ComponentSelector
- Object
- ComponentSelector
ImplementsCollection<Component>, Iterable<Component>, Set<Component>
A tool to facilitate selection and manipulation of UI components as sets. This uses fluent API style, similar to jQuery to make it easy to find UI components and modify them as groups.
Set Selection
Sets of components can either be created by explicitly adding components to the set, or by providing a “selector” string that specifies how the set should be formed. Some examples:
$("Label")- The set of all components on the current form with UIID=“Label”$("#AddressField")- The set of components with name=“AddressField”$("TextField#AddressField")- The set of components with UIID=TextField and Name=AddressField$("Label, Button")- Set of components in current form with UIID=“Label” or UIID=“Button”$("Label", myContainer)- Set of labels within the containermyContainer$("MyContainer *")- All descendants of the container with UIID=“MyContainer”. Will not include “MyContainer”.$("MyContainer > *")- All children of of the container with UIID=“MyContainer”.$("MyContainer > Label)- All children with UIID=Label of container with UIID=MyContainer$("Label").getParent()- All parent components of labels in the current form.
Tags
To make selection more flexible, you can “tag” components so that they can be easily targeted by a selector.
You can add tags to components using #addTags(java.lang.String...), and remove them using #removeTags(java.lang.String...).
Once you have tagged a component, it can be targeted quite easily using a selector. Tags are specified in a selector with a .
prefix. E.g.:
$(".my-tag")- The set of all components with tag “my-tag”.$("Label.my-tag")- The set of all components with tag “my-tag” and UIID=“Label”$("Label.my-tag.myother-tag")- The set of all components with tags “my-tag” and “myother-tag” and UIID=“Label”. Matches only components that include all of those tags.
Modifying Components in Set
While component selection alone in the ComponentSelector is quite powerful, the true power comes when
you start to operate on the entire set of components using the Fluent API of ComponentSelector. ComponentSelector
includes wrapper methods for most of the mutator methods of Component, Container, and a few other common
component types.
For example, the following two snippets are equivalent:
`for (Component c : $("Label")) {
c.getStyle().setFgColor(0xff0000);`
}
and
`$("Label").setFgColor(0xff0000);`
The second snippet is clearly easier to type and more compact. But we can take it further. The Fluent API style allows you to chain together multiple method calls. This even makes it desirable to operate on single-element sets. E.g.:
`Button myButton = $(new Button("Some text"))
.setUIID("Label")
.addTags("cell", "row-"+rowNum, "col-"+colNum, rowNum%2==0 ? "even":"odd")
.putClientProperty("row", rowNum)
.putClientProperty("col", colNum)
.asComponent(Button.class);`
The above snippet wraps a new Button in a ComponentSelector, then uses the fluent API to apply several properties
to the button, before using #asComponent() to return the Button itself.
API Overview
ComponentSelector includes a few different types of methods:
Wrapper methods for
Component,Container, etc… to operate on all applicable components in the set.Component Tree Traversal Methods to return other sets of components based on the current set. E.g.
#find(java.lang.String),#getParent(),#getComponentAt(int),#closest(java.lang.String),#nextSibling(),#prevSibling(),#parents(java.lang.String),#getComponentForm(), and many more.Effects. E.g.
#fadeIn(),#fadeOut(),#slideDown(),#slideUp(),#animateLayout(int),#animateHierarchy(int), etc..Convenience methods to help with common tasks. E.g.
#$(java.lang.Runnable)as a short-hand forDisplay#callSerially(java.lang.Runnable)Methods to implement
java.util.Setbecause ComponentSelector is a set.
Effects
The following is an example form that demonstrates the use of ComponentSelector to easily create effects on components in a form.
private void showEffectsForm() {
Form f = new Form("Effects", new BorderLayout());
applyToolbar(f);
Button fadeInFadeOut = $(new Button("Fade"))
.setIcon(FontImage.MATERIAL_BLUR_ON, 4)
.addActionListener(e->{
$(e).getParent().find(">*").fadeOutAndWait(1000).fadeInAndWait(1000);
})
.asComponent(Button.class);
Button slideUp = $(new Button("Slide Up"))
.setIcon(FontImage.MATERIAL_EXPAND_LESS)
.addActionListener(e->{
$(e).getParent().find(">*").slideUpAndWait(1000).slideDownAndWait(1000);
})
.asComponent(Button.class);
Button replace = $(new Button("Replace Fade/Slide"))
.setIcon(FontImage.MATERIAL_REDEEM)
.addActionListener(e->{
$(e).getParent()
.find(">*")
.replaceAndWait(c->{
return $(new Label("Replacement"))
.putClientProperty("origComponent", c)
.asComponent();
}, CommonTransitions.createFade(1000))
.replaceAndWait(c->{
Component orig = (Component)c.getClientProperty("origComponent");
if (orig != null) {
c.putClientProperty("origComponent", null);
return orig;
}
return c;
}, CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
})
.asComponent(Button.class);
Button replaceFlip = $(new Button("Replace Flip"))
.setIcon(FontImage.MATERIAL_REDEEM)
.addActionListener(e->{
$(e).getParent()
.find(">*")
.replaceAndWait(c->{
return $(new Label("Replacement"))
.putClientProperty("origComponent", c)
.asComponent();
},new FlipTransition(0xffffff, 1000))
.replaceAndWait(c->{
Component orig = (Component)c.getClientProperty("origComponent");
if (orig != null) {
c.putClientProperty("origComponent", null);
return orig;
}
return c;
},new FlipTransition(0xffffff, 1000));
})
.asComponent(Button.class);
Container root = GridLayout.encloseIn(3, fadeInFadeOut, slideUp, replace, replaceFlip);
f.addComponent(BorderLayout.CENTER, root);
f.show();
}
Advanced Use of Tags
The following shows the use of tags to help with striping a table, and selecting rows when clicked on.
private void showTableDemo() {
Form f = new Form("Table Demo", new BorderLayout());
applyToolbar(f);
CSVParser parser = new CSVParser();
String[][] data = null;
try {
data = parser.parse(Display.getInstance().getResourceAsStream(null, "/sample-data.csv"));
} catch (Exception ex) {
ex.printStackTrace();
}
if (data== null) {
ToastBar.showMessage("Failed to parse sample data", FontImage.MATERIAL_INFO);
return;
}
int numRows = data.length;
int numCols = data[0].length;
TableLayout tl = new TableLayout(numRows, numCols);
Container table = new Container(tl);
int rowNum = 0;
int colNum = 0;
for (String[] row : data) {
colNum = 0;
for (String cell : row) {
table.add(
tl.createConstraint(rowNum, colNum),
$(new Button(cell))
.setUIID("Label")
.addTags("cell", "row-"+rowNum, "col-"+colNum, rowNum%2==0 ? "even":"odd")
.putClientProperty("row", rowNum)
.putClientProperty("col", colNum)
.asComponent()
);
colNum++;
}
rowNum++;
}
$(".cell", table).setMargin(0).setPadding(0)
.addActionListener(e->{
// Action listener in each cell so that we can highlight the
// selected row
Component cell = (Component)e.getSource();
int row = (int)cell.getClientProperty("row");
int col = (int)cell.getClientProperty("col");
// Restore the style of the previously selected row
// and remove the selected-row tag
$(e).getParent().find(">.selected-row")
.each(c->{
// Restore the old style that we stored when we made
// the row selected originally (see below)
c.setUnselectedStyle((Style)c.getClientProperty("default-style"));
})
.removeTags("selected-row")
.getParent()
.repaint();
// Now add the "selected-row" tag, and modify the styles
$(e).getParent().find(">.row-"+row).addTags("selected-row")
.each(c->{
// Store the existing style so that we can
// reapply it when the row becomes unselected
Style oldStyle = new Style(c.getStyle());
c.putClientProperty("default-style", oldStyle);
})
.setBgColor(0x89cff0)
.setFgColor(0xffffff)
.setBgTransparency(255)
.getParent()
.repaint();
});
// Add striping to the table (make the even rows gray)
$(".even", table)
.setBgColor(0xcccccc)
.setBgTransparency(255);
f.addComponent(BorderLayout.CENTER, $(BoxLayout.encloseY(table)).setScrollableY(true).asComponent());
f.show();
}
See full Demo App in this Github Repo
Modifying Style Properties
Modifying styles deserves special mention because components have multiple Style objects associated with them.
Component#getStyle() returns the style of the component in its current state. Component#getPressedStyle()
gets the pressed style of the component, Component#getSelectedStyle() get its selected style, etc..
ComponentSelector wraps each of the getXXXStyle() methods of Component with corresponding methods
that return proxy styles for all components in the set. #getStyle() returns a proxy Style that proxies
all of the styles returned from each of the Component#getStyle() methods in the set. #getPressedStyle() returns
a proxy for all of the pressed styles, etc..
Example Modifying Text Color of All Buttons in a container when they are pressed only
`Style pressed = $("Button", myContainer).getPressedStyle();
pressed.setFgColor(0xff0000);`
A slightly more elegant pattern would be to use the #selectPressedStyle() method to set the default
style for mutations to “pressed”. Then we could use the fluent API of ComponentSelector to chain multiple style
mutations. E.g.:
`$("Button", myContainer)
.selectPressedStyle()
.setFgColor(0xffffff)
.setBgColor(0x0)
.setBgTransparency(255);`
A short-hand for this would be to add the :pressed pseudo-class to the selector. E.g.
`$("Button:pressed", myContainer)
.setFgColor(0xffffff)
.setBgColor(0x0)
.setBgTransparency(255);`
The following style pseudo-classes are supported:
:pressed - Same as calling
#selectPressedStyle():selected - Same as calling
#selectSelectedStyle():unselected - Same as calling
#selectUnselectedStyle():all - Same as calling
#selectAllStyles():* - Alias for :all
:disabled - Same as calling
#selectDisabledStyle()
You can chain calls to selectedXXXStyle(), enabling to chain together mutations of multiple different style properties. E.g To change the pressed foreground color, and then change the selected foreground color, you could do:
`$("Button", myContainer)
.selectPressedStyle()
.setFgColor(0x0000ff)
.selectSelectedStyle()
.setFgColor(0x00ff00);`
Filtering Sets
There are many ways to remove components from a set. Obviously you can use the standard java.util.Set methods
to explicitly remove components from your set:
`ComponentSelector sel = $("Button").remove(myButton, true);
// The set of all buttons on the current form, except myButton`
or
`ComponentSelector sel = $("Button").removeAll($(".some-tag"), true);
// The set of all buttons that do NOT contain the tag ".some-tag"`
You could also use the #filter(com.codename1.ui.ComponentSelector.Filter) to explicitly
declare which elements should be kept, and which should be discarded:
`ComponentSelector sel = $("Button").filter(c->{
return c.isVisible();`);
// The set of all buttons that are currently visible.
}
Tree Navigation
One powerful aspect of working with sets of components is that you can generate very specific sets of components using very simple queries. Consider the following queries:
$(myButton1, myButton2).getParent()- The set of parents of myButton1 and myButton2. If they have the same parent, then this set will only contain a single element: the common parent container. If they have different parents, then this set will include both parent containers.$(myButton).getParent().find(">TextField")- The set of siblings of myButton that have UIID=TextField$(myButton).closest(".some-tag")- The set containing the “nearest” parent container of myButton that has the tag “.some-tag”. If there are no matching components, then this will be an empty set. This is formed by crawling up the tree until it finds a matching component. Works the same as jQuery’s closest() method.$(".my-tag").getComponentAt(4)- The set of 5th child components of containers with tag “.my-tag”.
Nested types
interface ComponentSelector.ComponentClosure | Interface used for providing callbacks that receive a Component as input. |
interface ComponentSelector.ComponentMapper | Interface used by #map(com.codename1.ui.ComponentSelector.ComponentMapper) to form a new set of components based on the components in one set. |
interface ComponentSelector.Filter | Interface used by #filter(com.codename1.ui.ComponentSelector.Filter) to form a new set of components based on the components in one set. |
Constructors
public ComponentSelector(Component... cmps) | Creates a component selector that wraps the provided components. |
public ComponentSelector(Set<Component> cmps) | Creates a component selector that wraps the provided components. |
public ComponentSelector(String selector) | Creates a selector that will query the current form. |
public ComponentSelector(String selector, Component... roots) | Creates a selector with the provided roots. |
public ComponentSelector(String selector, Collection<Component> roots) | Creates a selector with the provided roots. |
Methods
Inherited methods
From Collection
Constructor details
ComponentSelector
public ComponentSelector(Component... cmps)#find(java.lang.String) to perform a query using this selector
as the roots.Parameters
cmpsComponent...- Components to add to this selector results.
ComponentSelector
public ComponentSelector(Set<Component> cmps)#find(java.lang.String) to perform a query using this selector
as the roots.Parameters
cmpsSet<Component>- Components to add to this selector results.
ComponentSelector
public ComponentSelector(String selector)Creates a selector that will query the current form. If there is no current form, then this selector will have no roots.
Generally it is better to provide a root explicitly using ComponentSelector.ComponentSelector(java.lang.String, com.codename1.ui.Component...)
to ensure that the selector has a tree to walk down.
Parameters
selectorString- The selector string.
ComponentSelector
public ComponentSelector(String selector, Component... roots)Parameters
selectorString- The selector string
rootsComponent...- The roots for this selector.
ComponentSelector
public ComponentSelector(String selector, Collection<Component> roots)Parameters
selectorString- The selector string
rootsCollection<Component>- The roots for this selector.
Method details
$
public static ComponentSelector $(Component... cmps)#select(Component...).Parameters
cmpsComponent...- Components to be includd in the set.
Returns
select
public static ComponentSelector select(Component... cmps)#$(com.codename1.ui.Component...)$
public static ComponentSelector $(ActionEvent e)#select(ActionEvent).Parameters
eActionEvent- The event whose source component is added to the set.
Returns
select
public static ComponentSelector select(ActionEvent e)#$(com.codename1.ui.events.ActionEvent)$
public static ComponentSelector $(Runnable r)#select(Runnable).Display#callSerially(java.lang.Runnable)Returns
select
public static ComponentSelector select(Runnable r)#$(java.lang.Runnable)$
public static ComponentSelector $(Set<Component> cmps)#select(Set).Parameters
cmpsSet<Component>- The components to include in the set.
Returns
select
public static ComponentSelector select(Set<Component> cmps)#$(java.util.Set)$
public static ComponentSelector $(String selector)#select(String).Parameters
selectorString- A selector string that defines which components to include in the set.
Returns
select
public static ComponentSelector select(String selector)#$(java.lang.String)$
public static ComponentSelector $(String selector, Component... roots)Component...).Parameters
selectorString- Selector string to define which components will be included in the set.
rootsComponent...- Roots for the selector to search. Only components within the roots’ subtrees will be included in the set.
Returns
select
public static ComponentSelector select(String selector, Component... roots)com.codename1.ui.Component...)$
public static ComponentSelector $(String selector, Collection<Component> roots)Collection).Parameters
selectorString- Selector string to define which components will be included in the set.
rootsCollection<Component>- Roots for the selector to search. Only components within the roots’ subtrees will be included in the set.
Returns
select
public static ComponentSelector select(String selector, Collection<Component> roots)java.util.Collection)each
public ComponentSelector each(ComponentSelector.ComponentClosure closure)Parameters
closureComponentSelector.ComponentClosure- Callback which will be called once for each component in the set.
Returns
map
public ComponentSelector map(ComponentSelector.ComponentMapper mapper)Parameters
mapperComponentSelector.ComponentMapper- The mapper which will be called once for each element in the set. The return value of the mapper function dictates which component should be included in the resulting set.
Returns
filter
public ComponentSelector filter(ComponentSelector.Filter filter)Parameters
filterComponentSelector.Filter- The filter function called for each element in the set. If it returns true, then the element is included in the resulting set. If false, it will not be included.
Returns
filter
public ComponentSelector filter(String selector)Parameters
selectorString- The selector to filter the found set on.
Returns
parent
public ComponentSelector parent(String selector)Parameters
selectorString- Selector to filter the parent components.
Returns
parents
public ComponentSelector parents(String selector)Parameters
selectorString- The selector to filter the ancestors.
Returns
closest
public ComponentSelector closest(String selector)Parameters
selectorString- The selector to use to match the nearest ancestor.
Returns
firstChild
public ComponentSelector firstChild()Returns
lastChild
public ComponentSelector lastChild()Returns
nextSibling
public ComponentSelector nextSibling()Returns
prevSibling
public ComponentSelector prevSibling()Returns
animateStyle
public ComponentSelector animateStyle(Style destStyle, int duration, SuccessCallback<ComponentSelector> callback)Parameters
destStyleStyle- The style to apply to the components via animation.
durationint- The duration of the animation (ms)
callbackSuccessCallback<ComponentSelector>- Callback to call after animation is complete.
Returns
fadeIn
public ComponentSelector fadeIn()Returns
fadeIn
public ComponentSelector fadeIn(int duration)Parameters
durationint- The duration of the fade in.
Returns
fadeIn
public ComponentSelector fadeIn(int duration, SuccessCallback<ComponentSelector> callback)Parameters
durationint- The duration of the fade in.
callbackSuccessCallback<ComponentSelector>- Callback to run when animation completes.
fadeInAndWait
public ComponentSelector fadeInAndWait()Returns
fadeInAndWait
public ComponentSelector fadeInAndWait(int duration)Parameters
durationint- The duration of the animation.
Returns
isVisible
public boolean isVisible()Returns
See also
setVisible
public ComponentSelector setVisible(boolean visible)Component#setVisible(boolean)Parameters
visibleboolean- True to make all components in result set visible. False for hidden.
Returns
isHidden
public boolean isHidden()Returns
See also
setHidden
public ComponentSelector setHidden(boolean b)Component#setHidden(boolean)fadeOut
public ComponentSelector fadeOut()Returns
fadeOut
public ComponentSelector fadeOut(int duration)Parameters
durationint- Duration of animation.
Returns
fadeOut
public ComponentSelector fadeOut(int duration, SuccessCallback<ComponentSelector> callback)Parameters
durationint- Duration of animation.
callbackSuccessCallback<ComponentSelector>- Callback to run when animation completes.
Returns
slideUp
public ComponentSelector slideUp(int duration)Parameters
durationint- Duration of animation
Returns
slideUp
public ComponentSelector slideUp(int duration, SuccessCallback<ComponentSelector> callback)Parameters
durationint- Duration of animation.
callbackSuccessCallback<ComponentSelector>- Callback to run when animation completes
Returns
slideUpAndWait
public ComponentSelector slideUpAndWait(int duration)Parameters
durationint- Duration of animation.
Returns
slideDown
public ComponentSelector slideDown()Returns
slideUp
public ComponentSelector slideUp()Returns
slideDown
public ComponentSelector slideDown(int duration)Parameters
durationint- Duration of animation.
Returns
slideDown
public ComponentSelector slideDown(int duration, SuccessCallback<ComponentSelector> callback)Parameters
durationint- Duration of animation.
callbackSuccessCallback<ComponentSelector>- Callback to run when animation completes.
Returns
slideDownAndWait
public ComponentSelector slideDownAndWait(int duration)Parameters
durationint- Duration of animation.
Returns
fadeOutAndWait
public ComponentSelector fadeOutAndWait(int duration)Parameters
durationint- Duration of animation.
Returns
replace
public ComponentSelector replace(ComponentSelector.ComponentMapper mapper)c.getParent().replace(c, replacement)) with an empty
transition.Parameters
mapperComponentSelector.ComponentMapper- Mapper that defines the replacements for each component in the set. If the mapper returns the input component, then no change is made for that component. A null return value cause the component to be removed from its parent. Returning a Component results in that component replacing the original component within its parent.
Returns
replace
public ComponentSelector replace(ComponentSelector.ComponentMapper mapper, Transition t)c.getParent().replace(c, replacement)) with the provided transition.Parameters
mapperComponentSelector.ComponentMapper- Mapper that defines the replacements for each component in the set. If the mapper returns the input component, then no change is made for that component. A null return value cause the component to be removed from its parent. Returning a Component results in that component replacing the original component within its parent.
tTransition- Transition to use for replacements.
Returns
replaceAndWait
public ComponentSelector replaceAndWait(ComponentSelector.ComponentMapper mapper, Transition t)c.getParent().replace(c, replacement)) with the provided transition.
Blocks the thread until the transition animation is complete.Parameters
mapperComponentSelector.ComponentMapper- Mapper that defines the replacements for each component in the set. If the mapper returns the input component, then no change is made for that component. A null return value cause the component to be removed from its parent. Returning a Component results in that component replacing the original component within its parent.
tTransition- Not documented.
Returns
find
public ComponentSelector find(String selector)Parameters
selectorString- The selector string.
Returns
iterator
public Iterator<Component> iterator()Returns
Iterator instance.getStyle
public Style getStyle()Component#getStyle() of each component in set.getStyle
public Style getStyle(Component component)Gets a style object for the given component that can be used to modify the component’s styles. This takes into account any state-pseudo classes that were used to create this selector so that the style returned will be appropriate.
E.g.
`ComponentSelector sel = new ComponentSelector("Button:pressed");
Style style = sel.getStyle(sel.get(0));
// This should be equivalent to sel.get(0).getPressedStyle()
sel = new ComponentSelector("Button");
style = sel.getStyle(sel.get(0));
// This should be equivalent to sel.get(0).getAllStyles()
sel = new ComponentSelector("Button:pressed, Button:selected");
style = sel.getStyle(sel.get(0));
// This should be same as
// Style.createProxyStyle(sel.get(0).getPressedStyle(), sel.get(0).getSelectedStyle())`
Parameters
componentComponent- The component whose style object we wish to obtain.
Returns
getSelectedStyle
public Style getSelectedStyle()Returns
setSelectedStyle
public ComponentSelector setSelectedStyle(Style style)Component#setSelectedStyle(com.codename1.ui.plaf.Style)selectSelectedStyle
public ComponentSelector selectSelectedStyle()Returns
See also
selectUnselectedStyle
public ComponentSelector selectUnselectedStyle()Returns
See also
selectPressedStyle
public ComponentSelector selectPressedStyle()Returns
See also
selectDisabledStyle
public ComponentSelector selectDisabledStyle()Returns
See also
selectAllStyles
public ComponentSelector selectAllStyles()Returns
See also
getUnselectedStyle
public Style getUnselectedStyle()Returns
setUnselectedStyle
public ComponentSelector setUnselectedStyle(Style style)Component#setUnselectedStyle(com.codename1.ui.plaf.Style)getPressedStyle
public Style getPressedStyle()Returns
setPressedStyle
public ComponentSelector setPressedStyle(Style style)Component#setPressedStyle(com.codename1.ui.plaf.Style)getDisabledStyle
public Style getDisabledStyle()Returns
setDisabledStyle
public ComponentSelector setDisabledStyle(Style style)Component#setDisabledStyle(com.codename1.ui.plaf.Style)getAllStyles
public Style getAllStyles()Returns
size
public int size()Returns
isEmpty
public boolean isEmpty()Returns
contains
public boolean contains(Object o)Returns
true if object is an element of this set, false
otherwise.toArray
public Object[] toArray()Returns
toArray
public <T> T[] toArray(T[] a)Parameters
aT[]- the array.
Returns
Throws
ArrayStoreException- when the type of an element in this set cannot be stored in the type of the specified array.
add
public boolean add(Component e)Returns
append
public ComponentSelector append(Component child)Container#add(com.codename1.ui.Component) padding child on first container
in this set.Parameters
childComponent- Component to add to container.
Returns
append
public ComponentSelector append(Object constraint, Component child)com.codename1.ui.Component) padding child on first container
in this set.append
public ComponentSelector append(ComponentSelector.ComponentMapper mapper)append
public ComponentSelector append(Object constraint, ComponentSelector.ComponentMapper mapper)add
public ComponentSelector add(Component e, boolean chain)#add(com.codename1.ui.Component)Parameters
eComponent- Component to add to set.
chainboolean- Dummy argument so that this version would have a different signature than
Set#add(java.lang.Object)
Returns
remove
public boolean remove(Object o)Returns
remove
public ComponentSelector remove(Object o, boolean chain)#remove(java.lang.Object).Parameters
oObject- The component to remove from set.
chainboolean- Dummy argument so that this version would have a different signature than
Set#remove(java.lang.Object)
Returns
containsAll
public boolean containsAll(Collection<?> c)Returns
true if all objects in the specified collection are
elements of this set, false otherwise.addAll
public boolean addAll(Collection<? extends Component> c)Returns
true if this set is modified, false otherwise.Throws
UnsupportedOperationException- when adding to this set is not supported.
ClassCastException- when the class of an object is inappropriate for this set.
IllegalArgumentException- when an object cannot be added to this set.
addAll
public ComponentSelector addAll(Collection<? extends Component> c, boolean chain)#addAll(java.util.Collection).Parameters
cCollection<? extends Component>- The set of components to add to this set.
chainboolean- Dummy argument so that this version would have a different signature than
#addAll(java.util.Collection)
Returns
asComponent
public Component asComponent()$(new Label()).setFgColor(0xff0000).asComponent()).Returns
asComponent
public <T extends Component> T asComponent(Class<T> type)$(new Label()).setFgColor(0xff0000).asComponent(Label.class)).Parameters
typeClass<T>- The type of component that is expected to be returned.
Returns
asList
public List<Component> asList()Returns
retainAll
public boolean retainAll(Collection<?> c)Returns
true if this set was modified, false otherwise.Throws
UnsupportedOperationException- when removing from this set is not supported.
retainAll
public ComponentSelector retainAll(Collection<?> c, boolean chain)#retainAll(java.util.Collection)Parameters
cCollection<?>- The collection to retain.
chainboolean- Dummy arg.
Returns
removeAll
public boolean removeAll(Collection<?> c)Returns
true if this set was modified, false otherwise.Throws
UnsupportedOperationException- when removing from this set is not supported.
removeAll
public ComponentSelector removeAll(Collection<?> c, boolean chain)#removeAll(java.util.Collection)Parameters
cCollection<?>- Collection with components to remove,
chainboolean- Dummy arg.
Returns
clear
public void clear()Throws
UnsupportedOperationException- when removing from this set is not supported.
clear
public ComponentSelector clear(boolean chain)Parameters
chainboolean- Dummy arg
Returns
toString
public String toString()addTags
public ComponentSelector addTags(String... tags)Parameters
tagsString...- Tags to add.
Returns
removeTags
public ComponentSelector removeTags(String... tags)getParent
public ComponentSelector getParent()Returns
setSameWidth
public ComponentSelector setSameWidth()Component#setSameWidth(com.codename1.ui.Component...). Passes all
components in the result set as parameters of this method, effectively making them all the
same width.setSameHeight
public ComponentSelector setSameHeight()Component#setSameHeight(com.codename1.ui.Component...). Passes all
components in the result set as parameters of this method, effectively making them all the
same height.clearClientProperties
public ComponentSelector clearClientProperties()Component#clearClientProperties().Returns
putClientProperty
public ComponentSelector putClientProperty(String key, Object value)java.lang.Object)Parameters
keyString- Property key
valueObject- Property value
Returns
getClientProperty
public Object getClientProperty(String key)Component#getClientProperty(java.lang.String)Parameters
keyString- The key of the client property to retrieve.
Returns
setDirtyRegion
public ComponentSelector setDirtyRegion(Rectangle rect)Component#setDirtyRegion(com.codename1.ui.geom.Rectangle)Parameters
rectRectangle- Dirty region
Returns
setX
public ComponentSelector setX(int x)Component#setX(int)setY
public ComponentSelector setY(int y)Component#setY(int)setWidth
public ComponentSelector setWidth(int width)Component#setWidth(int)setHeight
public ComponentSelector setHeight(int height)Component#setHeight(int)setPreferredSize
public ComponentSelector setPreferredSize(Dimension dim)Component#setPreferredSize(com.codename1.ui.geom.Dimension)setPreferredH
public ComponentSelector setPreferredH(int h)Component#setPreferredH(int)setPreferredW
public ComponentSelector setPreferredW(int w)Component#setPreferredW(int)setScrollSize
public ComponentSelector setScrollSize(Dimension size)Component#setScrollSizesetSize
public ComponentSelector setSize(Dimension size)Component#setSize(com.codename1.ui.geom.Dimension)setUIID
public ComponentSelector setUIID(String uiid)Component#setUIID(java.lang.String)remove
public ComponentSelector remove()Component#remove(). This will remove all of the components
in the current found set from their respective parents.addFocusListener
public ComponentSelector addFocusListener(FocusListener l)Component#addFocusListener(com.codename1.ui.events.FocusListener)removeFocusListener
public ComponentSelector removeFocusListener(FocusListener l)Component#removeFocusListener(com.codename1.ui.events.FocusListener)addScrollListener
public ComponentSelector addScrollListener(ScrollListener l)Component#addScrollListener(com.codename1.ui.events.ScrollListener)removeScrollListener
public ComponentSelector removeScrollListener(ScrollListener l)Component#removeScrollListener(com.codename1.ui.events.ScrollListener)setSelectCommandText
public ComponentSelector setSelectCommandText(String text)Component#setSelectCommandText(java.lang.String)setLabelForComponent
public ComponentSelector setLabelForComponent(Label l)Component#setLabelForComponent(com.codename1.ui.Label)paintBackgrounds
public ComponentSelector paintBackgrounds(Graphics g)Component#paintBackgrounds(com.codename1.ui.Graphics)paintComponent
public ComponentSelector paintComponent(Graphics g)Component#paintComponent(com.codename1.ui.Graphics)paint
public ComponentSelector paint(Graphics g)Component#paint(com.codename1.ui.Graphics)contains
public boolean contains(int x, int y)int)setFocusable
public ComponentSelector setFocusable(boolean focus)Component#setFocusable(boolean)repaint
public ComponentSelector repaint()Component#repaint()repaint
public ComponentSelector repaint(int x, int y, int w, int h)int, int, int)setScrollAnimationSpeed
public ComponentSelector setScrollAnimationSpeed(int speed)Component#setScrollAnimationSpeed(int)setSmoothScrolling
public ComponentSelector setSmoothScrolling(boolean smooth)Component#setSmoothScrolling(boolean)addDropListener
public ComponentSelector addDropListener(ActionListener l)Component#addDropListener(com.codename1.ui.events.ActionListener)removeDropListener
public ComponentSelector removeDropListener(ActionListener l)Component#removeDropListener(com.codename1.ui.events.ActionListener)addDragOverListener
public ComponentSelector addDragOverListener(ActionListener l)Component#addDragOverListener(com.codename1.ui.events.ActionListener)removeDragOverListener
public ComponentSelector removeDragOverListener(ActionListener l)Component#removeDragOverListener(com.codename1.ui.events.ActionListener)addPointerPressedListener
public ComponentSelector addPointerPressedListener(ActionListener l)Component#addPointerPressedListener(com.codename1.ui.events.ActionListener)addLongPressListener
public ComponentSelector addLongPressListener(ActionListener l)Component#addLongPressListener(com.codename1.ui.events.ActionListener)removePointerPressedListener
public ComponentSelector removePointerPressedListener(ActionListener l)Component#removePointerPressedListener(com.codename1.ui.events.ActionListener)removeLongPressListener
public ComponentSelector removeLongPressListener(ActionListener l)Component#removeLongPressListener(com.codename1.ui.events.ActionListener)addPointerReleasedListener
public ComponentSelector addPointerReleasedListener(ActionListener l)Component#addPointerReleasedListener(com.codename1.ui.events.ActionListener)removePointerReleasedListener
public ComponentSelector removePointerReleasedListener(ActionListener l)Component#removePointerReleasedListener(com.codename1.ui.events.ActionListener)addPointerDraggedListener
public ComponentSelector addPointerDraggedListener(ActionListener l)Component#addPointerDraggedListener(com.codename1.ui.events.ActionListener)removePointerDraggedListener
public ComponentSelector removePointerDraggedListener(ActionListener l)Component#removePointerDraggedListener(com.codename1.ui.events.ActionListener)requestFocus
public ComponentSelector requestFocus()Component#requestFocus()refreshTheme
public ComponentSelector refreshTheme()Component#refreshTheme()refreshTheme
public ComponentSelector refreshTheme(boolean merge)Component#refreshTheme(boolean)setCellRenderer
public ComponentSelector setCellRenderer(boolean cell)Component#setCellRenderer(boolean)setScrollVisible
public ComponentSelector setScrollVisible(boolean vis)Component#setScrollVisible(boolean)setEnabled
public ComponentSelector setEnabled(boolean enabled)Component#setEnabled(boolean)setName
public ComponentSelector setName(String name)Component#setName(java.lang.String)setRTL
public ComponentSelector setRTL(boolean rtl)Component#setRTL(boolean)setTactileTouch
public ComponentSelector setTactileTouch(boolean t)Component#setTactileTouch(boolean)setPropertyValue
public ComponentSelector setPropertyValue(String key, Object value)java.lang.Object)paintLockRelease
public ComponentSelector paintLockRelease()Component#paintLockRelease()setSnapToGrid
public ComponentSelector setSnapToGrid(boolean s)Component#setSnapToGrid(boolean)isIgnorePointerEvents
public boolean isIgnorePointerEvents()setIgnorePointerEvents
public ComponentSelector setIgnorePointerEvents(boolean ignore)setFlatten
public ComponentSelector setFlatten(boolean f)Component#setFlatten(boolean)setTensileLength
public ComponentSelector setTensileLength(int len)Component#setTensileLength(int)setGrabsPointerEvents
public ComponentSelector setGrabsPointerEvents(boolean g)Component#setGrabsPointerEvents(boolean)setScrollOpacityChangeSpeed
public ComponentSelector setScrollOpacityChangeSpeed(int scrollOpacityChangeSpeed)Component#setScrollOpacityChangeSpeed(int)growShrink
public ComponentSelector growShrink(int duration)Component#growShrink(int)setDraggable
public ComponentSelector setDraggable(boolean draggable)Component#setDraggable(boolean)setDropTarget
public ComponentSelector setDropTarget(boolean target)Component#setDropTarget(boolean)setHideInPortait
public ComponentSelector setHideInPortait(boolean hide)Component#setHideInPortrait(boolean)setHidden
public ComponentSelector setHidden(boolean b, boolean changeMargin)boolean)setComponentState
public ComponentSelector setComponentState(Object state)Component#setComponentState(java.lang.Object)setLeadComponent
public ComponentSelector setLeadComponent(Component lead)Container#setLeadComponent(com.codename1.ui.Component)setLayout
public ComponentSelector setLayout(Layout layout)Container#setLayout(com.codename1.ui.layouts.Layout)invalidate
public ComponentSelector invalidate()Container#invalidate()setShouldCalcPreferredSize
public ComponentSelector setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)Container#setShouldCalcPreferredSize(boolean)applyRTL
public ComponentSelector applyRTL(boolean rtl)Container#applyRTL(boolean)removeAll
public ComponentSelector removeAll()#clear(), which
removes components from the found set, but not from their respective parents.
Wraps Container#removeAll()revalidate
public ComponentSelector revalidate()Container#revalidate()forceRevalidate
public ComponentSelector forceRevalidate()Container#forceRevalidate()layoutContainer
public ComponentSelector layoutContainer()Container#layoutContainer()getComponentAt
public ComponentSelector getComponentAt(int index)Container#getComponentAt(int) on containers in this
found set. This effectively allows us to get all of the ith elements of all
matched components.Returns
indexth child of each container in the current found set.containsInSubtree
public boolean containsInSubtree(Component cmp)Container#contains(com.codename1.ui.Component)scrollComponentToVisible
public ComponentSelector scrollComponentToVisible(Component cmp)Container#scrollComponentToVisible(com.codename1.ui.Component)getComponentAt
public ComponentSelector getComponentAt(int x, int y)int) in the current found set.Returns
setScrollableX
public ComponentSelector setScrollableX(boolean b)Container#setScrollableX(boolean)setScrollableY
public ComponentSelector setScrollableY(boolean b)Container#setScrollableY(boolean)setScrollIncrement
public ComponentSelector setScrollIncrement(int b)Container#setScrollIncrement(int)findFirstFocusable
public ComponentSelector findFirstFocusable()Returns
See also
animateHierarchyAndWait
public ComponentSelector animateHierarchyAndWait(int duration)Container#animateHierarchyAndWait(int).animateHierarchy
public ComponentSelector animateHierarchy(int duration)Container#animateHierarchy(int)animateHierarchy
public ComponentSelector animateHierarchy(int duration, SuccessCallback<ComponentSelector> callback)Container#animateHierarchy(int).animateHierarchyFadeAndWait
public ComponentSelector animateHierarchyFadeAndWait(int duration, int startingOpacity)int).animateHierarchyFade
public ComponentSelector animateHierarchyFade(int duration, int startingOpacity)Container#animateHierarchyAndWait(int)Parameters
durationint- The duration of the animation.
startingOpacityint- The starting opacity.
Returns
animateHierarchyFade
public ComponentSelector animateHierarchyFade(int duration, int startingOpacity, SuccessCallback<ComponentSelector> callback)int).animateLayoutFadeAndWait
public ComponentSelector animateLayoutFadeAndWait(int duration, int startingOpacity)int).animateLayoutFade
public ComponentSelector animateLayoutFade(int duration, int startingOpacity)int).Returns
animateLayoutFade
public ComponentSelector animateLayoutFade(int duration, int startingOpacity, SuccessCallback<ComponentSelector> callback)int).animateLayout
public ComponentSelector animateLayout(int duration)Container#animateLayout(int)animateLayout
public ComponentSelector animateLayout(int duration, SuccessCallback<ComponentSelector> callback)Container#animateLayout(int).animateLayoutAndWait
public ComponentSelector animateLayoutAndWait(int duration)Container#animateLayoutAndWait(int)animateUnlayout
public ComponentSelector animateUnlayout(int duration, int opacity)int, java.lang.Runnable)animateUnlayout
public ComponentSelector animateUnlayout(int duration, int opacity, SuccessCallback<ComponentSelector> callback)int, java.lang.Runnable)Parameters
durationint- Not documented.
opacityint- Not documented.
callbackSuccessCallback<ComponentSelector>- Callback to run when animation has completed.
animateUnlayoutAndWait
public ComponentSelector animateUnlayoutAndWait(int duration, int opacity)int)getAnimationManager
public AnimationManager getAnimationManager()Returns
See also
getText
public String getText()setText
public ComponentSelector setText(String text)Parameters
textString- The text to set in the componnet.
setIcon
public ComponentSelector setIcon(Image icon)setIcon
public ComponentSelector setIcon(char materialIcon, Style style, float size)Parameters
materialIconchar- Material icon charcode.
styleStyle- The style for the icon.
sizefloat- The size for the icon. (in mm)
Returns
setIcon
public ComponentSelector setIcon(char materialIcon, float size)Parameters
materialIconchar- The icon charcode.
sizefloat- The size of the icon (in mm)
Returns
setIcon
public ComponentSelector setIcon(char materialIcon)Parameters
materialIconchar- The material icon charcode.
Returns
getComponentForm
public ComponentSelector getComponentForm()Returns
setVerticalAlignment
public ComponentSelector setVerticalAlignment(int valign)See also
setTextPosition
public ComponentSelector setTextPosition(int pos)See also
setIconUIID
public ComponentSelector setIconUIID(String uiid)Parameters
uiidString- The UIID for icons.
Returns
setGap
public ComponentSelector setGap(int gap)See also
setShiftText
public ComponentSelector setShiftText(int shift)See also
startTicker
public ComponentSelector startTicker(long delay, boolean rightToLeft)boolean)stopTicker
public ComponentSelector stopTicker()Label#stopTicker()setTickerEnabled
public ComponentSelector setTickerEnabled(boolean b)Label#setTickerEnabled(boolean)setEndsWith3Points
public ComponentSelector setEndsWith3Points(boolean b)Label#setEndsWith3Points(boolean)setMask
public ComponentSelector setMask(Object mask)Label#setMask(java.lang.Object)setMaskName
public ComponentSelector setMaskName(String name)Label#setMaskName(java.lang.String)setShouldLocalize
public ComponentSelector setShouldLocalize(boolean b)Label#setShouldLocalize(boolean)setShiftMillimeters
public ComponentSelector setShiftMillimeters(int b)Label#setShiftMillimeters(int)setShowEvenIfBlank
public ComponentSelector setShowEvenIfBlank(boolean b)Label#setShowEvenIfBlank(boolean)setLegacyRenderer
public ComponentSelector setLegacyRenderer(boolean b)Label#setLegacyRenderer(boolean)setAutoSizeMode
public ComponentSelector setAutoSizeMode(boolean b)Label#setAutoSizeMode(boolean)setCommand
public ComponentSelector setCommand(Command cmd)Button#setCommand(com.codename1.ui.Command)setRolloverPressedIcon
public ComponentSelector setRolloverPressedIcon(Image icon)Button#setRolloverPressedIcon(com.codename1.ui.Image)setRolloverIcon
public ComponentSelector setRolloverIcon(Image icon)Button#setRolloverIcon(com.codename1.ui.Image)setPressedIcon
public ComponentSelector setPressedIcon(Image icon)Button#setPressedIcon(com.codename1.ui.Image)setDisabledIcon
public ComponentSelector setDisabledIcon(Image icon)Button#setDisabledIcon(com.codename1.ui.Image)addActionListener
public ComponentSelector addActionListener(ActionListener l)removeActionListener
public ComponentSelector removeActionListener(ActionListener l)Parameters
lActionListener- The listener to remove
setEditable
public ComponentSelector setEditable(boolean b)TextArea#setEditable(boolean)addDataChangedListener
public ComponentSelector addDataChangedListener(DataChangedListener l)TextField#addDataChangedListener(com.codename1.ui.events.DataChangedListener)removeDataChangedListener
public ComponentSelector removeDataChangedListener(DataChangedListener l)TextField#removeDataChangedListener(com.codename1.ui.events.DataChangedListener)setDoneListener
public ComponentSelector setDoneListener(ActionListener l)TextField#setDoneListener(com.codename1.ui.events.ActionListener)setPadding
public ComponentSelector setPadding(int padding)Parameters
paddingint- Padding in pixels
stripMarginAndPadding
public ComponentSelector stripMarginAndPadding()Returns
See also
setPadding
public ComponentSelector setPadding(int top, int right, int bottom, int left)Parameters
topint- Top padding in pixels.
rightint- Right padding in pixels
bottomint- Bottom padding in pixels.
leftint- Left padding in pixels.
setPaddingMillimeters
public ComponentSelector setPaddingMillimeters(float top, float right, float bottom, float left)Parameters
topfloat- Top padding in mm.
rightfloat- Right padding in mm
bottomfloat- Bottom padding in mm.
leftfloat- Left padding in mm.
setPaddingMillimeters
public ComponentSelector setPaddingMillimeters(float topBottom, float leftRight)Parameters
topBottomfloat- Top and bottom padding in mm.
leftRightfloat- Left and right padding in mm.
setPaddingMillimeters
public ComponentSelector setPaddingMillimeters(float padding)Parameters
paddingfloat- Padding applied to all sides in mm.
setPadding
public ComponentSelector setPadding(int topBottom, int leftRight)Parameters
topBottomint- Top and bottom padding in pixels.
leftRightint- Left and right padding in pixels.
setPaddingPercent
public ComponentSelector setPaddingPercent(double padding)Parameters
paddingdouble- The padding expressed as a percent.
setPaddingPercent
public ComponentSelector setPaddingPercent(double topBottom, double leftRight)Parameters
topBottomdouble- Top and bottom padding as percentage of parent heights.
leftRightdouble- Left and right padding as percentage of parent widths.
setPaddingPercent
public ComponentSelector setPaddingPercent(double top, double right, double bottom, double left)Parameters
topdouble- Top padding as percentage of parent height.
rightdouble- Right padding as percentage of parent width.
bottomdouble- Bottom padding as percentage of parent height.
leftdouble- Left padding as percentage of parent width.
setMargin
public ComponentSelector setMargin(int margin)Parameters
marginint- Margin in pixels
setMargin
public ComponentSelector setMargin(int top, int right, int bottom, int left)Parameters
topint- Top margin in pixels.
rightint- Right margin in pixels
bottomint- Bottom margin in pixels.
leftint- Left margin in pixels.
setMargin
public ComponentSelector setMargin(int topBottom, int leftRight)Parameters
topBottomint- Top and bottom margin in pixels.
leftRightint- Left and right margin in pixels.
setMarginPercent
public ComponentSelector setMarginPercent(double margin)Parameters
margindouble- The margin expressed as a percent.
setMarginPercent
public ComponentSelector setMarginPercent(double topBottom, double leftRight)Parameters
topBottomdouble- Top and bottom margin as percentage of parent heights.
leftRightdouble- Left and right margin as percentage of parent widths.
setMarginPercent
public ComponentSelector setMarginPercent(double top, double right, double bottom, double left)Parameters
topdouble- Top margin as percentage of parent height.
rightdouble- Right margin as percentage of parent width.
bottomdouble- Bottom margin as percentage of parent height.
leftdouble- Left margin as percentage of parent width.
setMarginMillimeters
public ComponentSelector setMarginMillimeters(float top, float right, float bottom, float left)Parameters
topfloat- Top margin in mm.
rightfloat- Right margin in mm
bottomfloat- Bottom margin in mm.
leftfloat- Left margin in mm.
setMarginMillimeters
public ComponentSelector setMarginMillimeters(float topBottom, float leftRight)Parameters
topBottomfloat- Top and bottom margin in mm.
leftRightfloat- Left and right margin in mm.
setMarginMillimeters
public ComponentSelector setMarginMillimeters(float margin)Parameters
marginfloat- Margin applied to all sides in mm.
createProxyStyle
public Style createProxyStyle()merge
public ComponentSelector merge(Style style)setBgColor
public ComponentSelector setBgColor(int bgColor)Style#setBgColor(int)setAlignment
public ComponentSelector setAlignment(int alignment)Style#setAlignment(int)setBgImage
public ComponentSelector setBgImage(Image bgImage)Style#setBgImage(com.codename1.ui.Image)setBackgroundType
public ComponentSelector setBackgroundType(byte backgroundType)Style#setBackgroundType(byte)setBackgroundGradientStartColor
public ComponentSelector setBackgroundGradientStartColor(int startColor)Style#setBackgroundGradientStartColor(int)setBackgroundGradientEndColor
public ComponentSelector setBackgroundGradientEndColor(int endColor)(int)setBackgroundGradientRelativeX
public ComponentSelector setBackgroundGradientRelativeX(float x)Style#setBackgroundGradientRelativeX(float)setBackgroundGradientRelativeY
public ComponentSelector setBackgroundGradientRelativeY(float y)Style#setBackgroundGradientRelativeY(float)setBackgroundGradientRelativeSize
public ComponentSelector setBackgroundGradientRelativeSize(float size)Style#setBackgroundGradientRelativeSize(float)setFgColor
public ComponentSelector setFgColor(int color)Style#setFgColor(int)setFont
public ComponentSelector setFont(Font f)Style#setFont(com.codename1.ui.Font)setUnderline
public ComponentSelector setUnderline(boolean b)Style#setUnderline(boolean)set3DText
public ComponentSelector set3DText(boolean t, boolean raised)boolean)set3DTextNorth
public ComponentSelector set3DTextNorth(boolean north)Style#set3DTextNorth(boolean)setOverline
public ComponentSelector setOverline(boolean b)Style#setOverline(boolean)setStrikeThru
public ComponentSelector setStrikeThru(boolean b)Style#setStrikeThru(boolean)setTextDecoration
public ComponentSelector setTextDecoration(int textDecoration)Style#setTextDecoration(int)setBgTransparency
public ComponentSelector setBgTransparency(int bgTransparency)Style#setBgTransparency(byte)setOpacity
public ComponentSelector setOpacity(int opacity)Style#setOpacity(int)addStyleListener
public ComponentSelector addStyleListener(StyleListener l)Style#addStyleListener(com.codename1.ui.events.StyleListener)removeStyleListener
public ComponentSelector removeStyleListener(StyleListener l)Style#removeStyleListener(com.codename1.ui.events.StyleListener)removeStyleListeners
public ComponentSelector removeStyleListeners()Style#removeListeners()setBorder
public ComponentSelector setBorder(Border b)Style#setBorder(com.codename1.ui.plaf.Border)setBgPainter
public ComponentSelector setBgPainter(Painter bgPainter)Style#setBgPainter(com.codename1.ui.Painter)setFontSize
public ComponentSelector setFontSize(float size)Parameters
sizefloat- Font size in pixels.
setMaterialIcon
public ComponentSelector setMaterialIcon(char icon, float size)Parameters
iconchar- Material icon to set. See
char) sizefloat- The icon size in millimeters.
Returns
setCursor
public ComponentSelector setCursor(int cursor)setFontSizeMillimeters
public ComponentSelector setFontSizeMillimeters(float sizeMM)Parameters
sizeMMfloat- Font size in mm.
setFontSizePercent
public ComponentSelector setFontSizePercent(double sizePercentage)Parameters
sizePercentagedouble- Font size as a percentage of parent font size.
first
public ComponentSelector first()