Class ComponentSelector

java.lang.Object
com.codename1.ui.ComponentSelector
All Implemented Interfaces:
Iterable<Component>, Collection<Component>, Set<Component>

public class ComponentSelector extends Object implements 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 container myContainer

  • $("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 for Display#callSerially(java.lang.Runnable)

  • Methods to implement java.util.Set because 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".

  • Constructor Details

    • ComponentSelector

      public ComponentSelector(Component... cmps)

      Creates a component selector that wraps the provided components. The provided components are treated as the "results" of this selector. Not the roots. However you can use #find(java.lang.String) to perform a query using this selector as the roots.

      Parameters
      • cmps: Components to add to this selector results.
    • ComponentSelector

      public ComponentSelector(Set<Component> cmps)

      Creates a component selector that wraps the provided components. The provided components are treated as the "results" of this selector. Not the roots. However you can use #find(java.lang.String) to perform a query using this selector as the roots.

      Parameters
      • cmps: 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 invalid input: 'to ensure that the selector has a tree to walk down. #### Parameters - `selector`: The selector string.'

    • ComponentSelector

      public ComponentSelector(String selector, Component... roots)

      Creates a selector with the provided roots. This will only search through the subtrees of the provided roots to find results that match the provided selector string.

      Parameters
      • selector: The selector string

      • roots: The roots for this selector.

    • ComponentSelector

      public ComponentSelector(String selector, Collection<Component> roots)

      Creates a selector with the provided roots. This will only search through the subtrees of the provided roots to find results that match the provided selector string.

      Parameters
      • selector: The selector string

      • roots: The roots for this selector.

  • Method Details

    • $

      @Deprecated public static ComponentSelector $(Component... cmps)
      Deprecated.

      Wraps provided components in a ComponentSelector set.

      Parameters
      • cmps: Components to be includd in the set.
      Returns

      ComponentSelector with specified components.

      Deprecated

      Use #select(Component...).

    • select

      public static ComponentSelector select(Component... cmps)

      Alias of #$(com.codename1.ui.Component...)

      Parameters
      • cmps
    • $

      Deprecated.

      Creates a ComponentInspector with the source component of the provided event.

      Parameters
      • e: The event whose source component is added to the set.
      Returns

      A ComponentSelector with a single component - the source of the event.

      Deprecated

      Use #select(ActionEvent).

    • select

      public static ComponentSelector select(ActionEvent e)

      Alias of #$(com.codename1.ui.events.ActionEvent)

      Parameters
      • e
    • $

      @Deprecated public static ComponentSelector $(Runnable r)
      Deprecated.

      Wraps Display#callSerially(java.lang.Runnable)

      Parameters
      • r
      Returns

      Empty ComponentSelector.

      Deprecated

      Use #select(Runnable).

    • select

      public static ComponentSelector select(Runnable r)

      Alias of #$(java.lang.Runnable)

      Parameters
      • r
    • $

      @Deprecated public static ComponentSelector $(Set<Component> cmps)
      Deprecated.

      Creates a new ComponentSelector with the provided set of components.

      Parameters
      • cmps: The components to include in the set.
      Returns

      ComponentSelector with provided components.

      Deprecated

      Use #select(Set).

    • select

      public static ComponentSelector select(Set<Component> cmps)

      Alias of #$(java.util.Set)

      Parameters
      • cmps
    • $

      @Deprecated public static ComponentSelector $(String selector)
      Deprecated.

      Creates a new ComponentSelector with the components matched by the provided selector. The current form is used as the root for searches. Will throw a runtime exception if there is no current form.

      Parameters
      • selector: @param selector A selector string that defines which components to include in the set.
      Returns

      ComponentSelector with matching components.

      Deprecated

      Use #select(String).

    • select

      public static ComponentSelector select(String selector)

      Alias of #$(java.lang.String)

      Parameters
      • selector
    • $

      @Deprecated public static ComponentSelector $(String selector, Component... roots)
      Deprecated.

      Creates a ComponentSelector with the components matched by the provided selector in the provided roots' subtrees.

      Parameters
      • selector: Selector string to define which components will be included in the set.

      • roots: Roots for the selector to search. Only components within the roots' subtrees will be included in the set.

      Returns

      ComponentSelector with matching components.

      Deprecated

      Use Component...).

    • select

      public static ComponentSelector select(String selector, Component... roots)

      Alias of com.codename1.ui.Component...)

      Parameters
      • selector

      • roots

    • $

      @Deprecated public static ComponentSelector $(String selector, Collection<Component> roots)
      Deprecated.

      Creates a ComponentSelector with the components matched by the provided selector in the provided roots' subtrees.

      Parameters
      • selector: Selector string to define which components will be included in the set.

      • roots: Roots for the selector to search. Only components within the roots' subtrees will be included in the set.

      Returns

      ComponentSelector with matching components.

      Deprecated

      Use Collection).

    • select

      public static ComponentSelector select(String selector, Collection<Component> roots)

      Alias of java.util.Collection)

      Parameters
      • selector

      • roots

    • each

      Applies the given callback to each component in the set.

      Parameters
      • closure: Callback which will be called once for each component in the set.
      Returns

      Self for chaining.

    • map

      Creates a new set based on the elements of the current set and a mapping function which defines the elements that should be in the new set.

      Parameters
      • mapper: @param mapper 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

      A new set of components.

    • filter

      Creates a new set of components formed by filtering the current set using a filter function.

      Parameters
      • filter: @param 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

      A new set with the results of the filter.

    • filter

      public ComponentSelector filter(String selector)

      Filters the current found set against the given selector.

      Parameters
      • selector: The selector to filter the found set on.
      Returns

      A new set of elements matching the selector.

    • parent

      public ComponentSelector parent(String selector)

      Creates a new set of components consisting of all of the parents of components in this set. Only parent components matching the provided selector will be included in the set.

      Parameters
      • selector: Selector to filter the parent components.
      Returns

      New set with parents of elements in current set.

    • parents

      public ComponentSelector parents(String selector)

      Creates new set of components consisting of all of the ancestors of components in this set which match the provided selector.

      Parameters
      • selector: The selector to filter the ancestors.
      Returns

      New set with ancestors of elements in current set.

    • closest

      public ComponentSelector closest(String selector)

      Creates a new set of components consistng of all "closest" ancestors of components in this set which match the provided selector.

      Parameters
      • selector: The selector to use to match the nearest ancestor.
      Returns

      New set with ancestors of components in current set.

    • firstChild

      public ComponentSelector firstChild()

      Creates new set consisting of the first child of each component in the current set.

      Returns

      New set with first child of each component in current set.

    • lastChild

      public ComponentSelector lastChild()

      Creates new set consisting of the last child of each component in the current set.

      Returns

      New set with last child of each component in current set.

    • nextSibling

      public ComponentSelector nextSibling()

      Creates set of "next" siblings of components in this set.

      Returns

      New ComponentSelector with next siblings of this set.

    • prevSibling

      public ComponentSelector prevSibling()

      Creates set of "previous" siblings of components in this set.

      Returns

      New ComponentSelector with previous siblings of this set.

    • animateStyle

      public ComponentSelector animateStyle(Style destStyle, int duration, SuccessCallback<ComponentSelector> callback)

      Animates this set of components, replacing any modified style properties of the destination style to the components.

      Parameters
      • destStyle: The style to apply to the components via animation.

      • duration: The duration of the animation (ms)

      • callback: Callback to call after animation is complete.

      Returns

      Self for chaining

      See also
      • Component#createStyleAnimation(java.lang.String, int)
    • fadeIn

      public ComponentSelector fadeIn()

      Fade in this set of components. Prior to calling this, the component visibility should be set to "false". This uses the default duration of 500ms.

      Returns

      Self for chaining.

    • fadeIn

      public ComponentSelector fadeIn(int duration)

      Fade in this set of components. Prior to calling this, the component visibility should be set to "false".

      Parameters
      • duration: The duration of the fade in.
      Returns

      Self for chaining.

    • fadeIn

      public ComponentSelector fadeIn(int duration, SuccessCallback<ComponentSelector> callback)

      Fade in this set of components. Prior to calling this, the component visibility should be set to "false".

      Parameters
      • duration: The duration of the fade in.

      • callback: Callback to run when animation completes.

    • fadeInAndWait

      public ComponentSelector fadeInAndWait()

      Fades in this component and blocks until animation is complete.

      Returns

      Self for chaining.

    • fadeInAndWait

      public ComponentSelector fadeInAndWait(int duration)

      Fades in this component and blocks until animation is complete.

      Parameters
      • duration: The duration of the animation.
      Returns

      Self for chaining.

    • isVisible

      public boolean isVisible()

      Returns true if the first component in this set is visible.

      Returns

      True if first component in this set is visible.

      See also
      • Component#isVisible()
    • setVisible

      public ComponentSelector setVisible(boolean visible)

      Wrapper for Component#setVisible(boolean)

      Parameters
      • visible: True to make all components in result set visible. False for hidden.
      Returns

      Self for chaining.

    • isHidden

      public boolean isHidden()

      Returns true if first component in this set is hidden.

      Returns

      True if first component in set is hidden.

      See also
      • Component#isHidden()
    • setHidden

      public ComponentSelector setHidden(boolean b)

      Wraps Component#setHidden(boolean)

      Parameters
      • b
    • fadeOut

      public ComponentSelector fadeOut()

      Fades out components in this set. Uses default duration of 500ms.

      Returns

      Self for chaining.

    • fadeOut

      public ComponentSelector fadeOut(int duration)

      Fades out components in this set.

      Parameters
      • duration: Duration of animation.
      Returns

      Self for chaining.

    • fadeOut

      public ComponentSelector fadeOut(int duration, SuccessCallback<ComponentSelector> callback)

      Fades out components in this set.

      Parameters
      • duration: Duration of animation.

      • callback: Callback to run when animation completes.

      Returns

      Self for chaining.

    • slideUp

      public ComponentSelector slideUp(int duration)

      Hide the matched components with a sliding motion.

      Parameters
      • duration: Duration of animation
      Returns

      Self for chaining.

    • slideUp

      public ComponentSelector slideUp(int duration, SuccessCallback<ComponentSelector> callback)

      Hide the matched elements with a sliding motion.

      Parameters
      • duration: Duration of animation.

      • callback: Callback to run when animation completes

      Returns

      Self for chaining.

    • slideUpAndWait

      public ComponentSelector slideUpAndWait(int duration)

      Hide the matched elements with a sliding motion. Blocks until animation is complete.

      Parameters
      • duration: Duration of animation.
      Returns

      Self for chaining.

    • slideDown

      public ComponentSelector slideDown()

      Display the matched elements with a sliding motion. Uses default duration of 500ms

      Returns

      Self for chaining.

    • slideUp

      public ComponentSelector slideUp()

      Hide the matched elements with a sliding motion. Uses default duration of 500ms

      Returns

      Self for chaining.

    • slideDown

      public ComponentSelector slideDown(int duration)

      Display the matched elements with a sliding motion.

      Parameters
      • duration: Duration of animation.
      Returns

      Self for chaining.

    • slideDown

      public ComponentSelector slideDown(int duration, SuccessCallback<ComponentSelector> callback)

      Display the matched elements with a sliding motion.

      Parameters
      • duration: Duration of animation.

      • callback: Callback to run when animation completes.

      Returns

      Self for chaining.

    • slideDownAndWait

      public ComponentSelector slideDownAndWait(int duration)

      Display the matched elements with a sliding motion. Blocks until animation is complete.

      Parameters
      • duration: Duration of animation.
      Returns

      Self for chaining.

    • fadeOutAndWait

      public ComponentSelector fadeOutAndWait(int duration)

      Hide the matched elements by fading them to transparent. Blocks thread until animation is complete.

      Parameters
      • duration: Duration of animation.
      Returns

      Self for chaining.

    • replace

      Replaces the matched components within respective parents with replacements defined by the provided mapper. Replacements are replaced in the UI itself (i.e. c.getParent().replace(c, replacement)) with an empty transition.

      Parameters
      • mapper: @param mapper 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

      A new ComponentSelector with the replacement components.

    • replace

      Replaces the matched components within respective parents with replacements defined by the provided mapper. Replacements are replaced in the UI itself (i.e. c.getParent().replace(c, replacement)) with the provided transition.

      Parameters
      • mapper: @param mapper 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.

      • t: Transition to use for replacements.

      Returns

      A new ComponentSelector with the replacement components.

    • replaceAndWait

      Replaces the matched components within respective parents with replacements defined by the provided mapper. Replacements are replaced in the UI itself (i.e. c.getParent().replace(c, replacement)) with the provided transition. Blocks the thread until the transition animation is complete.

      Parameters
      • mapper: @param mapper 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.

      • t

      Returns

      A new ComponentSelector with the replacement components.

    • find

      public ComponentSelector find(String selector)

      Uses the results of this selector as the roots to create a new selector with the provided selector string.

      Parameters
      • selector: The selector string.
      Returns

      A new ComponentSelector with the results of the query.

    • iterator

      public Iterator<Component> iterator()
      Returns the results of this selector.
      Specified by:
      iterator in interface Collection<Component>
      Specified by:
      iterator in interface Iterable<Component>
      Specified by:
      iterator in interface Set<Component>
    • getStyle

      public Style getStyle()
      Gets a proxy style that wraps the result of 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
      • component: The component whose style object we wish to obtain.
      Returns

      A style object that will allow us to modify the style of the given component.

    • getSelectedStyle

      public Style getSelectedStyle()

      Returns a proxy style for all of the selected styles of the components in this set.

      Returns
      Returns:
      Proxy style to easily change properties of the selected styles of all components in this set.
    • setSelectedStyle

      public ComponentSelector setSelectedStyle(Style style)

      Sets selected style of all components in found set. Wraps Component#setSelectedStyle(com.codename1.ui.plaf.Style)

      Parameters
      • style
    • selectSelectedStyle

      public ComponentSelector selectSelectedStyle()

      Sets the current style to the selected style. Style mutation methods called after calling this method will modify the components' "selected style".

      Returns

      Self for chaining.

      See also
      • Component#getSelectedStyle()
    • selectUnselectedStyle

      public ComponentSelector selectUnselectedStyle()

      Sets the current style to the unselected style. Style mutation methods called after calling this method will modify the components' "unselected style".

      Returns

      Self for chaining.

      See also
      • Component#getUnselectedStyle()
    • selectPressedStyle

      public ComponentSelector selectPressedStyle()

      Sets the current style to the pressed style. Style mutation methods called after calling this method will modify the components' "pressed style".

      Returns

      Self for chaining.

      See also
      • Component#getPressedStyle()
    • selectDisabledStyle

      public ComponentSelector selectDisabledStyle()

      Sets the current style to the disabled style. Style mutation methods called after calling this method will modify the components' "disabled style".

      Returns

      Self for chaining.

      See also
      • Component#getDisabledStyle()
    • selectAllStyles

      public ComponentSelector selectAllStyles()

      Sets the current style to each component's ALL STYLES proxy style. Style mutation methods called after calling this method will modify the components' "all styles" proxy style.

      Returns

      Self for chaining.

      See also
      • Component#getAllStyles()
    • getUnselectedStyle

      public Style getUnselectedStyle()

      Returns a proxy style for all of the unselected styles of the components in this set.

      Returns
      Returns:
      Proxy style to easily change properties of the unselected styles of all components in this set.
    • setUnselectedStyle

      public ComponentSelector setUnselectedStyle(Style style)

      Sets unselected style of all components in found set. Wraps Component#setUnselectedStyle(com.codename1.ui.plaf.Style)

      Parameters
      • style
    • getPressedStyle

      public Style getPressedStyle()

      Returns a proxy style for all of the pressed styles of the components in this set.

      Returns
      Returns:
      Proxy style to easily change properties of the pressed styles of all components in this set.
    • setPressedStyle

      public ComponentSelector setPressedStyle(Style style)

      Sets pressed style of all components in found set. Wraps Component#setPressedStyle(com.codename1.ui.plaf.Style)

      Parameters
      • style
    • getDisabledStyle

      public Style getDisabledStyle()

      Returns a proxy style for all of the disabled styles of the components in this set.

      Returns
      Returns:
      Proxy style to easily change properties of the disabled styles of all components in this set.
    • setDisabledStyle

      public ComponentSelector setDisabledStyle(Style style)

      Sets disabled style of all components in found set. Wraps Component#setDisabledStyle(com.codename1.ui.plaf.Style)

      Parameters
      • style
    • getAllStyles

      public Style getAllStyles()

      Returns a proxy style for all of the "all" styles of the components in this set.

      Returns
      Returns:
      Proxy style to easily change properties of the "all" styles of all components in this set.
    • size

      public int size()
      Returns number of results found.
      Specified by:
      size in interface Collection<Component>
      Specified by:
      size in interface Set<Component>
    • isEmpty

      public boolean isEmpty()
      Returns

      True if there were no results.

      Specified by:
      isEmpty in interface Collection<Component>
      Specified by:
      isEmpty in interface Set<Component>
    • contains

      public boolean contains(Object o)

      Checks if an object is contained in result set.

      Parameters
      • o
      Specified by:
      contains in interface Collection<Component>
      Specified by:
      contains in interface Set<Component>
    • toArray

      public Object[] toArray()
      Returns results as an array.
      Specified by:
      toArray in interface Collection<Component>
      Specified by:
      toArray in interface Set<Component>
    • toArray

      public <T> T[] toArray(T[] a)
      Returns results as an array.
      Specified by:
      toArray in interface Collection<Component>
      Specified by:
      toArray in interface Set<Component>
    • add

      public boolean add(Component e)

      Explicitly adds a component to the result set.

      Parameters
      • e
      Returns

      True on success

      Specified by:
      add in interface Collection<Component>
      Specified by:
      add in interface Set<Component>
    • append

      public ComponentSelector append(Component child)

      Appends a child component to the first container in this set. Same as calling Container#add(com.codename1.ui.Component) padding child on first container in this set.

      Parameters
      • child: Component to add to container.
      Returns

      Self for chaining.

    • append

      public ComponentSelector append(Object constraint, Component child)

      Appends a child component to the first container in this set. Same as calling com.codename1.ui.Component) padding child on first container in this set.

      Parameters
      • constraint

      • child

    • append

      Append a child element to each container in this set. The mapper callback will receive a Container as input (that is the parent to be added to), and should return a Component that is to be added to it. If the mapper returns null, then nothing is added to that container.

      Parameters
      • mapper
    • append

      public ComponentSelector append(Object constraint, ComponentSelector.ComponentMapper mapper)

      Append a child element to each container in this set. The mapper callback will receive a Container as input (that is the parent to be added to), and should return a Component that is to be added to it. If the mapper returns null, then nothing is added to that container.

      Parameters
      • constraint

      • mapper

    • add

      public ComponentSelector add(Component e, boolean chain)

      Fluent API wrapper for #add(com.codename1.ui.Component)

      Parameters
      • e: Component to add to set.

      • chain: Dummy argument so that this version would have a different signature than Set#add(java.lang.Object)

      Returns

      Self for chaining.

    • remove

      public boolean remove(Object o)

      Explicitly removes a component from the result set.

      Parameters
      • o
      Returns

      Self for chaining.

      Specified by:
      remove in interface Collection<Component>
      Specified by:
      remove in interface Set<Component>
    • remove

      public ComponentSelector remove(Object o, boolean chain)

      Fluent API wrapper for #remove(java.lang.Object).

      Parameters
      • o: The component to remove from set.

      • chain: Dummy argument so that this version would have a different signature than Set#remove(java.lang.Object)

      Returns

      Self for chaining.

    • containsAll

      public boolean containsAll(Collection<?> c)

      Checks if the result set contains all of the components found in the provided collection.

      Parameters
      • c
      Specified by:
      containsAll in interface Collection<Component>
      Specified by:
      containsAll in interface Set<Component>
    • addAll

      public boolean addAll(Collection<? extends Component> c)

      Adds all components in the given collection to the result set.

      Parameters
      • c
      Specified by:
      addAll in interface Collection<Component>
      Specified by:
      addAll in interface Set<Component>
    • addAll

      public ComponentSelector addAll(Collection<? extends Component> c, boolean chain)

      Fluent API wrapper for #addAll(java.util.Collection).

      Parameters
      • c: The set of components to add to this set.

      • chain: Dummy argument so that this version would have a different signature than #addAll(java.util.Collection)

      Returns

      Self for chaining.

    • asComponent

      public Component asComponent()

      Returns the first component in this set. This is useful for single component sets (e.g. $(new Label()).setFgColor(0xff0000).asComponent()).

      Returns

      The first component in this set.

    • asComponent

      public <T extends Component> T asComponent(Class<T> type)

      Returns the first component in this set. This is useful for single component sets (e.g. $(new Label()).setFgColor(0xff0000).asComponent(Label.class)).

      Parameters
      • The: type of component to return

      • type: The type of component that is expected to be returned.

      Returns

      The first component in this set.

    • asList

      public List<Component> asList()

      Returns the components of this set as a List. Note that order of elements is not maintained since ComponentSelector is a set (i.e. has no notion of element order).

      Returns

      The components in this set as a list.

    • retainAll

      public boolean retainAll(Collection<?> c)

      Retains only elements of the result set that are contained in the provided collection.

      Parameters
      • c
      Specified by:
      retainAll in interface Collection<Component>
      Specified by:
      retainAll in interface Set<Component>
    • retainAll

      public ComponentSelector retainAll(Collection<?> c, boolean chain)

      Fluent API wrapper for #retainAll(java.util.Collection)

      Parameters
      • c: The collection to retain.

      • chain: Dummy arg.

      Returns

      Self for chaining.

    • removeAll

      public boolean removeAll(Collection<?> c)

      Removes all of the components in the provided collection from the result set.

      Parameters
      • c
      Specified by:
      removeAll in interface Collection<Component>
      Specified by:
      removeAll in interface Set<Component>
    • removeAll

      public ComponentSelector removeAll(Collection<?> c, boolean chain)

      Fluent API wrapper for #removeAll(java.util.Collection)

      Parameters
      • c: Collection with components to remove,

      • chain: Dummy arg.

      Returns

      Self for chaining.

    • clear

      public void clear()
      Clears the result set.
      Specified by:
      clear in interface Collection<Component>
      Specified by:
      clear in interface Set<Component>
    • clear

      public ComponentSelector clear(boolean chain)

      Fluent API wrapper for (@link #clear()}

      Parameters
      • chain: Dummy arg
      Returns

      Self for chaining.

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addTags

      public ComponentSelector addTags(String... tags)

      Adds the given tags to all elements in the result set.

      Parameters
      • tags: Tags to add.
      Returns

      Self for chaining.

    • removeTags

      public ComponentSelector removeTags(String... tags)

      Removes the given tags from all elements in the result set.

      Parameters
      • tags
    • getParent

      public ComponentSelector getParent()

      Gets the set of all "parent" components of components in the result set.

      Returns
      Returns:
      New Component selector with respective parents of the components in the current result set.
    • setSameWidth

      public ComponentSelector setSameWidth()
      Wrapper for 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()
      Wrapper for 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()

      Wrapper for Component#clearClientProperties().

      Returns

      Self for Chaining.

    • putClientProperty

      public ComponentSelector putClientProperty(String key, Object value)

      Wrapper for java.lang.Object)

      Parameters
      • key: Property key

      • value: Property value

      Returns

      Self for chaining.

    • getClientProperty

      public Object getClientProperty(String key)

      Gets a client property from the first component in the set. Wraps Component#getClientProperty(java.lang.String)

      Parameters
      • key: The key of the client property to retrieve.
      Returns

      The value of the client property.

    • setDirtyRegion

      public ComponentSelector setDirtyRegion(Rectangle rect)

      Wrapper for Component#setDirtyRegion(com.codename1.ui.geom.Rectangle)

      Parameters
      • rect: Dirty region
      Returns

      Self for chaining.

    • setX

      public ComponentSelector setX(int x)

      Wrapper for Component#setX(int)

      Parameters
      • x
    • setY

      public ComponentSelector setY(int y)

      Wrapper for Component#setY(int)

      Parameters
      • y
    • setWidth

      public ComponentSelector setWidth(int width)

      Wrapper for Component#setWidth(int)

      Parameters
      • width
    • setHeight

      public ComponentSelector setHeight(int height)

      Wrapper for Component#setHeight(int)

      Parameters
      • height
    • setPreferredSize

      public ComponentSelector setPreferredSize(Dimension dim)

      Wrapper for Component#setPreferredSize(com.codename1.ui.geom.Dimension)

      Parameters
      • dim
    • setPreferredH

      public ComponentSelector setPreferredH(int h)

      Wrapper for Component#setPreferredH(int)

      Parameters
      • h
    • setPreferredW

      public ComponentSelector setPreferredW(int w)

      Wrapper for Component#setPreferredW(int)

      Parameters
      • w
    • setScrollSize

      public ComponentSelector setScrollSize(Dimension size)

      Wrapper for Component#setScrollSize

      Parameters
      • size
    • setSize

      public ComponentSelector setSize(Dimension size)

      Wrapper for Component#setSize(com.codename1.ui.geom.Dimension)

      Parameters
      • size
    • setUIID

      public ComponentSelector setUIID(String uiid)

      Wrapper for Component#setUIID(java.lang.String)

      Parameters
      • uiid
    • remove

      public ComponentSelector remove()
      Wrapper for Component#remove(). This will remove all of the components in the current found set from their respective parents.
    • addFocusListener

      public ComponentSelector addFocusListener(FocusListener l)

      Adds a focus listener to all components in found set. Wraps Component#addFocusListener(com.codename1.ui.events.FocusListener)

      Parameters
      • l
    • removeFocusListener

      public ComponentSelector removeFocusListener(FocusListener l)

      Removes focus listener from all components in found set. Wraps Component#removeFocusListener(com.codename1.ui.events.FocusListener)

      Parameters
      • l
    • addScrollListener

      public ComponentSelector addScrollListener(ScrollListener l)

      Adds scroll listener to all components in found set. Wraps Component#addScrollListener(com.codename1.ui.events.ScrollListener)

      Parameters
      • l
    • removeScrollListener

      public ComponentSelector removeScrollListener(ScrollListener l)

      Removes scroll listener from all components in found set. Wraps Component#removeScrollListener(com.codename1.ui.events.ScrollListener)

      Parameters
      • l
    • setSelectCommandText

      public ComponentSelector setSelectCommandText(String text)

      Sets select command text on all components in found set. Wraps Component#setSelectCommandText(java.lang.String)

      Parameters
      • text
    • setLabelForComponent

      public ComponentSelector setLabelForComponent(Label l)

      Wraps Component#setLabelForComponent(com.codename1.ui.Label)

      Parameters
      • l
    • paintBackgrounds

      public ComponentSelector paintBackgrounds(Graphics g)

      Wraps Component#paintBackgrounds(com.codename1.ui.Graphics)

      Parameters
      • g
    • paintComponent

      public ComponentSelector paintComponent(Graphics g)

      Wraps Component#paintComponent(com.codename1.ui.Graphics)

      Parameters
      • g
    • paint

      public ComponentSelector paint(Graphics g)

      Wraps Component#paint(com.codename1.ui.Graphics)

      Parameters
      • g
    • contains

      public boolean contains(int x, int y)

      Returns true if any of the components in the found set contains the provided coordinate. Wraps int)

      Parameters
      • x

      • y

    • setFocusable

      public ComponentSelector setFocusable(boolean focus)

      Sets all components in the found set focusability. Wraps Component#setFocusable(boolean)

      Parameters
      • focus
    • repaint

      public ComponentSelector repaint()
      Wraps Component#repaint()
    • repaint

      public ComponentSelector repaint(int x, int y, int w, int h)

      Wraps int, int, int)

      Parameters
      • x

      • y

      • w

      • h

    • setScrollAnimationSpeed

      public ComponentSelector setScrollAnimationSpeed(int speed)

      Wraps Component#setScrollAnimationSpeed(int)

      Parameters
      • speed
    • setSmoothScrolling

      public ComponentSelector setSmoothScrolling(boolean smooth)

      Wraps Component#setSmoothScrolling(boolean)

      Parameters
      • smooth
    • addDropListener

      public ComponentSelector addDropListener(ActionListener l)

      Adds a drop listener to all components in found set. Wraps Component#addDropListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • removeDropListener

      public ComponentSelector removeDropListener(ActionListener l)

      Removes a drop listener from all components in found set. Wraps Component#removeDropListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • addDragOverListener

      public ComponentSelector addDragOverListener(ActionListener l)

      Adds drag over listener to all components in found set. Wraps Component#addDragOverListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • removeDragOverListener

      public ComponentSelector removeDragOverListener(ActionListener l)

      Removes drag over listener from all components in found set. Wraps Component#removeDragOverListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • addPointerPressedListener

      public ComponentSelector addPointerPressedListener(ActionListener l)

      Adds pointer pressed listener to all components in found set. Wraps Component#addPointerPressedListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • addLongPressListener

      public ComponentSelector addLongPressListener(ActionListener l)

      Adds long pointer pressed listener to all components in found set. Wraps Component#addLongPressListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • removePointerPressedListener

      public ComponentSelector removePointerPressedListener(ActionListener l)

      Removes pointer pressed listener from all components in found set. Wraps Component#removePointerPressedListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • removeLongPressListener

      public ComponentSelector removeLongPressListener(ActionListener l)

      Removes long pointer pressed listener from all components in found set. Wraps Component#removeLongPressListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • addPointerReleasedListener

      public ComponentSelector addPointerReleasedListener(ActionListener l)

      Adds pointer released listener to all components in found set. Wraps Component#addPointerReleasedListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • removePointerReleasedListener

      public ComponentSelector removePointerReleasedListener(ActionListener l)

      Removes pointer released listener from all components in found set. Wraps Component#removePointerReleasedListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • addPointerDraggedListener

      public ComponentSelector addPointerDraggedListener(ActionListener l)

      Adds pointer dragged listener to all components in found set. Wraps Component#addPointerDraggedListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • removePointerDraggedListener

      public ComponentSelector removePointerDraggedListener(ActionListener l)

      REmoves pointer dragged listener from all components in found set. Wraps Component#removePointerDraggedListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • requestFocus

      public ComponentSelector requestFocus()
      Wraps Component#requestFocus()
    • refreshTheme

      public ComponentSelector refreshTheme()
      Wraps Component#refreshTheme()
    • refreshTheme

      public ComponentSelector refreshTheme(boolean merge)

      Wraps Component#refreshTheme(boolean)

      Parameters
      • merge
    • setCellRenderer

      public ComponentSelector setCellRenderer(boolean cell)

      Wraps Component#setCellRenderer(boolean)

      Parameters
      • cell
    • setScrollVisible

      public ComponentSelector setScrollVisible(boolean vis)

      Wraps Component#setScrollVisible(boolean)

      Parameters
      • vis
    • setEnabled

      public ComponentSelector setEnabled(boolean enabled)

      Wraps Component#setEnabled(boolean)

      Parameters
      • enabled
    • setName

      public ComponentSelector setName(String name)

      Wraps Component#setName(java.lang.String)

      Parameters
      • name
    • setRTL

      public ComponentSelector setRTL(boolean rtl)

      Wraps Component#setRTL(boolean)

      Parameters
      • rtl
    • setTactileTouch

      public ComponentSelector setTactileTouch(boolean t)

      Wraps Component#setTactileTouch(boolean)

      Parameters
      • t
    • setPropertyValue

      public ComponentSelector setPropertyValue(String key, Object value)

      Wraps java.lang.Object)

      Parameters
      • key

      • value

    • paintLockRelease

      public ComponentSelector paintLockRelease()
      Wraps Component#paintLockRelease()
    • setSnapToGrid

      public ComponentSelector setSnapToGrid(boolean s)

      Wraps Component#setSnapToGrid(boolean)

      Parameters
      • s
    • isIgnorePointerEvents

      public boolean isIgnorePointerEvents()
    • setIgnorePointerEvents

      public ComponentSelector setIgnorePointerEvents(boolean ignore)
    • setFlatten

      public ComponentSelector setFlatten(boolean f)

      Wraps Component#setFlatten(boolean)

      Parameters
      • f
    • setTensileLength

      public ComponentSelector setTensileLength(int len)

      Wraps Component#setTensileLength(int)

      Parameters
      • len
    • setGrabsPointerEvents

      public ComponentSelector setGrabsPointerEvents(boolean g)

      Wraps Component#setGrabsPointerEvents(boolean)

      Parameters
      • g
    • setScrollOpacityChangeSpeed

      public ComponentSelector setScrollOpacityChangeSpeed(int scrollOpacityChangeSpeed)

      Wraps Component#setScrollOpacityChangeSpeed(int)

      Parameters
      • scrollOpacityChangeSpeed
    • growShrink

      public ComponentSelector growShrink(int duration)

      Wraps Component#growShrink(int)

      Parameters
      • duration
    • setDraggable

      public ComponentSelector setDraggable(boolean draggable)

      Wraps Component#setDraggable(boolean)

      Parameters
      • draggable
    • setDropTarget

      public ComponentSelector setDropTarget(boolean target)

      Wraps Component#setDropTarget(boolean)

      Parameters
      • target
    • setHideInPortait

      public ComponentSelector setHideInPortait(boolean hide)

      Wraps Component#setHideInPortrait(boolean)

      Parameters
      • hide
    • setHidden

      public ComponentSelector setHidden(boolean b, boolean changeMargin)

      Wraps boolean)

      Parameters
      • b

      • changeMargin

    • setComponentState

      public ComponentSelector setComponentState(Object state)

      Wraps Component#setComponentState(java.lang.Object)

      Parameters
      • state
    • setLeadComponent

      public ComponentSelector setLeadComponent(Component lead)

      Wraps Container#setLeadComponent(com.codename1.ui.Component)

      Parameters
      • lead
    • setLayout

      public ComponentSelector setLayout(Layout layout)

      Wraps Container#setLayout(com.codename1.ui.layouts.Layout)

      Parameters
      • layout
    • invalidate

      public ComponentSelector invalidate()
      Wraps Container#invalidate()
    • setShouldCalcPreferredSize

      public ComponentSelector setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)

      Wraps Container#setShouldCalcPreferredSize(boolean)

      Parameters
      • shouldCalcPreferredSize
    • applyRTL

      public ComponentSelector applyRTL(boolean rtl)

      Wraps Container#applyRTL(boolean)

      Parameters
      • rtl
    • removeAll

      public ComponentSelector removeAll()
      This removes all children from all containers in found set. Not to be confused with #clear(), which removes components from the found set, but not from their respective parents. Wraps Container#removeAll()
    • revalidate

      public ComponentSelector revalidate()
      Wraps Container#revalidate()
    • forceRevalidate

      public ComponentSelector forceRevalidate()
      Wraps Container#forceRevalidate()
    • layoutContainer

      public ComponentSelector layoutContainer()
      Wraps Container#layoutContainer()
    • getComponentAt

      public ComponentSelector getComponentAt(int index)

      This returns a new ComponentSelector which includes a set of all results of calling Container#getComponentAt(int) on containers in this found set. This effectively allows us to get all of the ith elements of all matched components.

      Parameters
      • index
      Returns

      New ComponentSelector with indexth child of each container in the current found set.

    • containsInSubtree

      public boolean containsInSubtree(Component cmp)

      Returns true if any of the containers in the current found set contains the provided component in its subtree. Wraps Container#contains(com.codename1.ui.Component)

      Parameters
      • cmp
    • scrollComponentToVisible

      public ComponentSelector scrollComponentToVisible(Component cmp)

      Wraps Container#scrollComponentToVisible(com.codename1.ui.Component)

      Parameters
      • cmp
    • getComponentAt

      public ComponentSelector getComponentAt(int x, int y)

      Returns new ComponentSelector with the set of all components returned from calling int) in the current found set.

      Parameters
      • x

      • y

      Returns

      New ComponentSelector with components at the given coordinates.

    • setScrollableX

      public ComponentSelector setScrollableX(boolean b)

      Wraps Container#setScrollableX(boolean)

      Parameters
      • b
    • setScrollableY

      public ComponentSelector setScrollableY(boolean b)

      Wraps Container#setScrollableY(boolean)

      Parameters
      • b
    • setScrollIncrement

      public ComponentSelector setScrollIncrement(int b)

      Wraps Container#setScrollIncrement(int)

      Parameters
      • b
    • findFirstFocusable

      public ComponentSelector findFirstFocusable()

      Creates new ComponentSelector with the set of first focusable elements of each of the containers in the current result set.

      Returns
      Returns:

      New component selector with first focusable element of each container in current found set.

      See also
      • Container#findFirstFocusable()
    • animateHierarchyAndWait

      public ComponentSelector animateHierarchyAndWait(int duration)

      Wraps Container#animateHierarchyAndWait(int).

      Parameters
      • duration
    • animateHierarchy

      public ComponentSelector animateHierarchy(int duration)

      Animates the hierarchy of containers in this set. Wraps Container#animateHierarchy(int)

      Parameters
      • duration
    • animateHierarchy

      public ComponentSelector animateHierarchy(int duration, SuccessCallback<ComponentSelector> callback)

      Wraps Container#animateHierarchy(int).

      Parameters
      • duration

      • callback

    • animateHierarchyFadeAndWait

      public ComponentSelector animateHierarchyFadeAndWait(int duration, int startingOpacity)

      Wraps int).

      Parameters
      • duration

      • startingOpacity

    • animateHierarchyFade

      public ComponentSelector animateHierarchyFade(int duration, int startingOpacity)

      Wraps Container#animateHierarchyAndWait(int)

      Parameters
      • duration: The duration of the animation.

      • startingOpacity: The starting opacity.

      Returns

      Self for chaining.

    • animateHierarchyFade

      public ComponentSelector animateHierarchyFade(int duration, int startingOpacity, SuccessCallback<ComponentSelector> callback)

      Wraps int).

      Parameters
      • duration

      • startingOpacity

      • callback

    • animateLayoutFadeAndWait

      public ComponentSelector animateLayoutFadeAndWait(int duration, int startingOpacity)

      Wraps int).

      Parameters
      • duration

      • startingOpacity

    • animateLayoutFade

      public ComponentSelector animateLayoutFade(int duration, int startingOpacity)

      Animates layout with fade on all containers in this set. Wraps int).

      Parameters
      • duration

      • startingOpacity

      Returns

      Self for chaining.

    • animateLayoutFade

      public ComponentSelector animateLayoutFade(int duration, int startingOpacity, SuccessCallback<ComponentSelector> callback)

      Wraps int).

      Parameters
      • duration

      • startingOpacity

      • callback

    • animateLayout

      public ComponentSelector animateLayout(int duration)

      Wraps Container#animateLayout(int)

      Parameters
      • duration
    • animateLayout

      public ComponentSelector animateLayout(int duration, SuccessCallback<ComponentSelector> callback)

      Wraps Container#animateLayout(int).

      Parameters
      • duration

      • callback

    • animateLayoutAndWait

      public ComponentSelector animateLayoutAndWait(int duration)

      Wraps Container#animateLayoutAndWait(int)

      Parameters
      • duration
    • animateUnlayout

      public ComponentSelector animateUnlayout(int duration, int opacity)

      Wraps int, java.lang.Runnable)

      Parameters
      • duration

      • opacity

    • animateUnlayout

      public ComponentSelector animateUnlayout(int duration, int opacity, SuccessCallback<ComponentSelector> callback)

      Wraps int, java.lang.Runnable)

      Parameters
      • duration

      • opacity

      • callback: Callback to run when animation has completed.

    • animateUnlayoutAndWait

      public ComponentSelector animateUnlayoutAndWait(int duration, int opacity)

      Wraps int)

      Parameters
      • duration

      • opacity

    • getAnimationManager

      public AnimationManager getAnimationManager()

      Gets the AnimationManager for the components in this set.

      Returns

      The AnimationManager for the components in this set.

      See also
      • Component#getAnimationManager()
    • getText

      public String getText()
      Gets the text on the first component in this set that supports this property. Currently this works with Label, TextArea, SpanLabel, and SpanButtons, and subclasses thereof.
    • setText

      public ComponentSelector setText(String text)

      Sets the text on all components in found set that support this. Currently this works with Label, TextArea, SpanLabel, and SpanButtons, and subclasses thereof.

      Parameters
      • text: The text to set in the componnet.
    • setIcon

      public ComponentSelector setIcon(Image icon)

      Sets the icon for components in found set. Only relevant to Labels, SpanLabels, and SpanButtons, and subclasses thereof.

      Parameters
      • icon
    • setIcon

      public ComponentSelector setIcon(char materialIcon, Style style, float size)

      Sets the icons of all elements in this set to a material icon.

      Parameters
      • materialIcon: Material icon charcode.

      • style: The style for the icon.

      • size: The size for the icon. (in mm)

      Returns

      Self for chaining.

      See also
      • FontImage#createMaterial(char, java.lang.String, float)
    • setIcon

      public ComponentSelector setIcon(char materialIcon, float size)

      Sets the icon of all elements in this set to a material icon. This will use the foreground color of each label as the icon's foreground color.

      Parameters
      • materialIcon: The icon charcode.

      • size: The size of the icon (in mm)

      Returns

      Self for chaining

      See also
      • FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
    • setIcon

      public ComponentSelector setIcon(char materialIcon)

      Sets the icon of all elements in this set to a material icon. This will use the foreground color of the label.

      Parameters
      • materialIcon: The material icon charcode.
      Returns

      Self for chaining.

    • getComponentForm

      public ComponentSelector getComponentForm()

      Gets the set of all component forms from components in this set.

      Returns

      New ComponentSelector with forms all components in this set.

    • setVerticalAlignment

      public ComponentSelector setVerticalAlignment(int valign)

      Sets vertical alignment of text.

      Parameters
      • valign
      See also
      • Label#setVerticalAlignment(int)
    • setTextPosition

      public ComponentSelector setTextPosition(int pos)

      Sets text position of text. Only relevant to labels.

      Parameters
      • pos
      See also
      • Label#setTextPosition(int)
    • setIconUIID

      public ComponentSelector setIconUIID(String uiid)

      Sets the Icon UIID of elements in found set.

      Parameters
      • uiid: The UIID for icons.
      Returns

      Self for chaining.

      Since

      7.0

      See also
      • IconHolder#setIconUIID(java.lang.String)
    • setGap

      public ComponentSelector setGap(int gap)

      Sets gap. Only relevant to labels.

      Parameters
      • gap
      See also
      • Label#setGap(int)
    • setShiftText

      public ComponentSelector setShiftText(int shift)

      Sets shift text. Only relevant to labels.

      Parameters
      • shift
      See also
      • Label#setShiftText(int)
    • startTicker

      public ComponentSelector startTicker(long delay, boolean rightToLeft)

      Wraps boolean)

      Parameters
      • delay

      • rightToLeft

    • stopTicker

      public ComponentSelector stopTicker()
      Wraps Label#stopTicker()
    • setTickerEnabled

      public ComponentSelector setTickerEnabled(boolean b)

      Wraps Label#setTickerEnabled(boolean)

      Parameters
      • b
    • setEndsWith3Points

      public ComponentSelector setEndsWith3Points(boolean b)

      Wraps Label#setEndsWith3Points(boolean)

      Parameters
      • b
    • setMask

      public ComponentSelector setMask(Object mask)

      Wraps Label#setMask(java.lang.Object)

      Parameters
      • mask
    • setMaskName

      public ComponentSelector setMaskName(String name)

      Wraps Label#setMaskName(java.lang.String)

      Parameters
      • name
    • setShouldLocalize

      public ComponentSelector setShouldLocalize(boolean b)

      Wraps Label#setShouldLocalize(boolean)

      Parameters
      • b
    • setShiftMillimeters

      public ComponentSelector setShiftMillimeters(int b)

      Wraps Label#setShiftMillimeters(int)

      Parameters
      • b
    • setShowEvenIfBlank

      public ComponentSelector setShowEvenIfBlank(boolean b)

      Wraps Label#setShowEvenIfBlank(boolean)

      Parameters
      • b
    • setLegacyRenderer

      public ComponentSelector setLegacyRenderer(boolean b)

      Wraps Label#setLegacyRenderer(boolean)

      Parameters
      • b
    • setAutoSizeMode

      public ComponentSelector setAutoSizeMode(boolean b)

      Wraps Label#setAutoSizeMode(boolean)

      Parameters
      • b
    • setCommand

      public ComponentSelector setCommand(Command cmd)

      Wraps Button#setCommand(com.codename1.ui.Command)

      Parameters
      • cmd
    • setRolloverPressedIcon

      public ComponentSelector setRolloverPressedIcon(Image icon)

      Wraps Button#setRolloverPressedIcon(com.codename1.ui.Image)

      Parameters
      • icon
    • setRolloverIcon

      public ComponentSelector setRolloverIcon(Image icon)

      Wraps Button#setRolloverIcon(com.codename1.ui.Image)

      Parameters
      • icon
    • setPressedIcon

      public ComponentSelector setPressedIcon(Image icon)

      Wraps Button#setPressedIcon(com.codename1.ui.Image)

      Parameters
      • icon
    • setDisabledIcon

      public ComponentSelector setDisabledIcon(Image icon)

      Wraps Button#setDisabledIcon(com.codename1.ui.Image)

      Parameters
      • icon
    • addActionListener

      public ComponentSelector addActionListener(ActionListener l)

      Adds action listener to applicable components in found set. Currently this will apply to Buttons, Lists, Sliders, TextAreas, OnOffSwitches, SpanButtons, and subclasses thereof.

      Parameters
      • l
    • removeActionListener

      public ComponentSelector removeActionListener(ActionListener l)

      Removes action listeners from components in set.

      Parameters
      • l: The listener to remove
      Since

      7.0

    • setEditable

      public ComponentSelector setEditable(boolean b)

      Wraps TextArea#setEditable(boolean)

      Parameters
      • b
    • addDataChangedListener

      public ComponentSelector addDataChangedListener(DataChangedListener l)

      Wraps TextField#addDataChangedListener(com.codename1.ui.events.DataChangedListener)

      Parameters
      • l
    • removeDataChangedListener

      public ComponentSelector removeDataChangedListener(DataChangedListener l)

      Wraps TextField#removeDataChangedListener(com.codename1.ui.events.DataChangedListener)

      Parameters
      • l
    • setDoneListener

      public ComponentSelector setDoneListener(ActionListener l)

      Wraps TextField#setDoneListener(com.codename1.ui.events.ActionListener)

      Parameters
      • l
    • setPadding

      public ComponentSelector setPadding(int padding)

      Sets padding to all sides of found set components in pixels.

      Parameters
      • padding: Padding in pixels
      See also
      • #getStyle(com.codename1.ui.Component)
    • stripMarginAndPadding

      public ComponentSelector stripMarginAndPadding()

      Strips margin and padding from components in found set.

      Returns

      Self for chaining.

      Since

      7.0

      See also
      • Style#stripMarginAndPadding()
    • setPadding

      public ComponentSelector setPadding(int top, int right, int bottom, int left)

      Sets padding to all components in found set.

      Parameters
      • top: Top padding in pixels.

      • right: Right padding in pixels

      • bottom: Bottom padding in pixels.

      • left: Left padding in pixels.

      See also
      • #getStyle(com.codename1.ui.Component)
    • setPaddingMillimeters

      public ComponentSelector setPaddingMillimeters(float top, float right, float bottom, float left)

      Sets padding to all components in found set in millimeters.

      Parameters
      • top: Top padding in mm.

      • right: Right padding in mm

      • bottom: Bottom padding in mm.

      • left: Left padding in mm.

      See also
      • #getStyle(com.codename1.ui.Component)
    • setPaddingMillimeters

      public ComponentSelector setPaddingMillimeters(float topBottom, float leftRight)

      Sets padding in millimeters to all components in found set.

      Parameters
      • topBottom: Top and bottom padding in mm.

      • leftRight: Left and right padding in mm.

      See also
      • #getStyle(com.codename1.ui.Component)
    • setPaddingMillimeters

      public ComponentSelector setPaddingMillimeters(float padding)

      Sets padding to all components in found set.

      Parameters
      • padding: Padding applied to all sides in mm.
    • setPadding

      public ComponentSelector setPadding(int topBottom, int leftRight)

      Sets padding on all components in found set.

      Parameters
      • topBottom: Top and bottom padding in pixels.

      • leftRight: Left and right padding in pixels.

    • setPaddingPercent

      public ComponentSelector setPaddingPercent(double padding)

      Sets the padding on all components in found set as a percentage of their respective parents' dimensions. Horizontal padding is set as a percentage of parent width. Vertical padding is set as a percentage of parent height.

      Parameters
      • padding: The padding expressed as a percent.
    • setPaddingPercent

      public ComponentSelector setPaddingPercent(double topBottom, double leftRight)

      Sets padding on all components in found set as a percentage of their respective parents' dimensions.

      Parameters
      • topBottom: Top and bottom padding as percentage of parent heights.

      • leftRight: Left and right padding as percentage of parent widths.

    • setPaddingPercent

      public ComponentSelector setPaddingPercent(double top, double right, double bottom, double left)

      Sets padding on all components in found set as a percentage of their respective parents' dimensions.

      Parameters
      • top: Top padding as percentage of parent height.

      • right: Right padding as percentage of parent width.

      • bottom: Bottom padding as percentage of parent height.

      • left: Left padding as percentage of parent width.

    • setMargin

      public ComponentSelector setMargin(int margin)

      Sets margin to all sides of found set components in pixels.

      Parameters
      • margin: Margin in pixels
      See also
      • #getStyle(com.codename1.ui.Component)
    • setMargin

      public ComponentSelector setMargin(int top, int right, int bottom, int left)

      Sets margin to all components in found set.

      Parameters
      • top: Top margin in pixels.

      • right: Right margin in pixels

      • bottom: Bottom margin in pixels.

      • left: Left margin in pixels.

      See also
      • #getStyle(com.codename1.ui.Component)
    • setMargin

      public ComponentSelector setMargin(int topBottom, int leftRight)

      Sets margin on all components in found set.

      Parameters
      • topBottom: Top and bottom margin in pixels.

      • leftRight: Left and right margin in pixels.

    • setMarginPercent

      public ComponentSelector setMarginPercent(double margin)

      Sets the margin on all components in found set as a percentage of their respective parents' dimensions. Horizontal margin is set as a percentage of parent width. Vertical margin is set as a percentage of parent height.

      Parameters
      • margin: The margin expressed as a percent.
    • setMarginPercent

      public ComponentSelector setMarginPercent(double topBottom, double leftRight)

      Sets margin on all components in found set as a percentage of their respective parents' dimensions.

      Parameters
      • topBottom: Top and bottom margin as percentage of parent heights.

      • leftRight: Left and right margin as percentage of parent widths.

    • setMarginPercent

      public ComponentSelector setMarginPercent(double top, double right, double bottom, double left)

      Sets margin on all components in found set as a percentage of their respective parents' dimensions.

      Parameters
      • top: Top margin as percentage of parent height.

      • right: Right margin as percentage of parent width.

      • bottom: Bottom margin as percentage of parent height.

      • left: Left margin as percentage of parent width.

    • setMarginMillimeters

      public ComponentSelector setMarginMillimeters(float top, float right, float bottom, float left)

      Sets margin to all components in found set in millimeters.

      Parameters
      • top: Top margin in mm.

      • right: Right margin in mm

      • bottom: Bottom margin in mm.

      • left: Left margin in mm.

      See also
      • #getStyle(com.codename1.ui.Component)
    • setMarginMillimeters

      public ComponentSelector setMarginMillimeters(float topBottom, float leftRight)

      Sets margin in millimeters to all components in found set.

      Parameters
      • topBottom: Top and bottom margin in mm.

      • leftRight: Left and right margin in mm.

      See also
      • #getStyle(com.codename1.ui.Component)
    • setMarginMillimeters

      public ComponentSelector setMarginMillimeters(float margin)

      Sets margin to all components in found set.

      Parameters
      • margin: Margin applied to all sides in mm.
    • createProxyStyle

      public Style createProxyStyle()

      Creates a proxy style to mutate the styles of all component styles in found set.

      See also
      • #getStyle(com.codename1.ui.Component)

      • Style#createProxyStyle(com.codename1.ui.plaf.Style...)

    • merge

      public ComponentSelector merge(Style style)

      Merges style with all styles of components in current found set.

      Parameters
      • style
      See also
      • Style#merge(com.codename1.ui.plaf.Style)

      • #getStyle(com.codename1.ui.Component)

    • setBgColor

      public ComponentSelector setBgColor(int bgColor)

      Wraps Style#setBgColor(int)

      Parameters
      • bgColor
      See also
      • #getStyle(com.codename1.ui.Component)
    • setAlignment

      public ComponentSelector setAlignment(int alignment)

      Wraps Style#setAlignment(int)

      Parameters
      • alignment
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBgImage

      public ComponentSelector setBgImage(Image bgImage)

      Wraps Style#setBgImage(com.codename1.ui.Image)

      Parameters
      • bgImage
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBackgroundType

      public ComponentSelector setBackgroundType(byte backgroundType)

      Wraps Style#setBackgroundType(byte)

      Parameters
      • backgroundType
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBackgroundGradientStartColor

      public ComponentSelector setBackgroundGradientStartColor(int startColor)

      Wraps Style#setBackgroundGradientStartColor(int)

      Parameters
      • startColor
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBackgroundGradientEndColor

      public ComponentSelector setBackgroundGradientEndColor(int endColor)

      Wraps (int)

      Parameters
      • endColor
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBackgroundGradientRelativeX

      public ComponentSelector setBackgroundGradientRelativeX(float x)

      Wraps Style#setBackgroundGradientRelativeX(float)

      Parameters
      • x
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBackgroundGradientRelativeY

      public ComponentSelector setBackgroundGradientRelativeY(float y)

      Wraps Style#setBackgroundGradientRelativeY(float)

      Parameters
      • y
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBackgroundGradientRelativeSize

      public ComponentSelector setBackgroundGradientRelativeSize(float size)

      Wraps Style#setBackgroundGradientRelativeSize(float)

      Parameters
      • size
      See also
      • #getStyle(com.codename1.ui.Component)
    • setFgColor

      public ComponentSelector setFgColor(int color)

      Wraps Style#setFgColor(int)

      Parameters
      • color
      See also
      • #getStyle(com.codename1.ui.Component)
    • setFont

      public ComponentSelector setFont(Font f)

      Wraps Style#setFont(com.codename1.ui.Font)

      Parameters
      • f
      See also
      • #getStyle(com.codename1.ui.Component)
    • setUnderline

      public ComponentSelector setUnderline(boolean b)

      Wraps Style#setUnderline(boolean)

      Parameters
      • b
      See also
      • #getStyle(com.codename1.ui.Component)
    • set3DText

      public ComponentSelector set3DText(boolean t, boolean raised)

      Wraps boolean)

      Parameters
      • t

      • raised

      See also
      • #getStyle(com.codename1.ui.Component)
    • set3DTextNorth

      public ComponentSelector set3DTextNorth(boolean north)

      Wraps Style#set3DTextNorth(boolean)

      Parameters
      • north
      See also
      • #getStyle(com.codename1.ui.Component)
    • setOverline

      public ComponentSelector setOverline(boolean b)

      Wraps Style#setOverline(boolean)

      Parameters
      • b
      See also
      • #getStyle(com.codename1.ui.Component)
    • setStrikeThru

      public ComponentSelector setStrikeThru(boolean b)

      Wraps Style#setStrikeThru(boolean)

      Parameters
      • b
      See also
      • #getStyle(com.codename1.ui.Component)
    • setTextDecoration

      public ComponentSelector setTextDecoration(int textDecoration)

      Wraps Style#setTextDecoration(int)

      Parameters
      • textDecoration
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBgTransparency

      public ComponentSelector setBgTransparency(int bgTransparency)

      Wraps Style#setBgTransparency(byte)

      Parameters
      • bgTransparency
      See also
      • #getStyle(com.codename1.ui.Component)
    • setOpacity

      public ComponentSelector setOpacity(int opacity)

      Wraps Style#setOpacity(int)

      Parameters
      • opacity
      See also
      • #getStyle(com.codename1.ui.Component)
    • addStyleListener

      public ComponentSelector addStyleListener(StyleListener l)

      Wraps Style#addStyleListener(com.codename1.ui.events.StyleListener)

      Parameters
      • l
      See also
      • #getStyle(com.codename1.ui.Component)
    • removeStyleListener

      public ComponentSelector removeStyleListener(StyleListener l)

      Wraps Style#removeStyleListener(com.codename1.ui.events.StyleListener)

      Parameters
      • l
      See also
      • #getStyle(com.codename1.ui.Component)
    • removeStyleListeners

      public ComponentSelector removeStyleListeners()

      Wraps Style#removeListeners()

      See also
      • #getStyle(com.codename1.ui.Component)
    • setBorder

      public ComponentSelector setBorder(Border b)

      Wraps Style#setBorder(com.codename1.ui.plaf.Border)

      Parameters
      • b
      See also
      • #getStyle(com.codename1.ui.Component)
    • setBgPainter

      public ComponentSelector setBgPainter(Painter bgPainter)

      Wraps Style#setBgPainter(com.codename1.ui.Painter)

      Parameters
      • bgPainter
      See also
      • #getStyle(com.codename1.ui.Component)
    • setFontSize

      public ComponentSelector setFontSize(float size)

      Sets the font size of all components in found set. In pixels.

      Parameters
      • size: Font size in pixels.
      See also
      • #getStyle(com.codename1.ui.Component)
    • setMaterialIcon

      public ComponentSelector setMaterialIcon(char icon, float size)

      Sets the material icon of all labels in the set.

      Parameters
      • icon: Material icon to set. See char)

      • size: The icon size in millimeters.

      Returns

      Self for chaining.

      Since

      7.0

    • setCursor

      public ComponentSelector setCursor(int cursor)
    • setFontSizeMillimeters

      public ComponentSelector setFontSizeMillimeters(float sizeMM)

      Sets the font size of all components in found set. In millimeters.

      Parameters
      • sizeMM: Font size in mm.
    • setFontSizePercent

      public ComponentSelector setFontSizePercent(double sizePercentage)

      Sets the fonts size of all components in the found set as a percentage of the font size of the components' respective parents.

      Parameters
      • sizePercentage: Font size as a percentage of parent font size.
    • first

      public ComponentSelector first()

      Returns a set with the first element of the current set, or an empty set if the current set is empty.

      Returns

      A ComponentSelector with 0 or 1 element.

      Since

      7.0