How to get component from component name in codenameone?

SmedleyDSlap

If I know what the name of the component is which was set by component.setName(name) how can I use the name to get the component object.

akash kubavat

if you have added that component via designer then you can directly access by

findWhatEverComponentName() (with below TextField name you can access by findMyTf())

but if you have added component by code then one of the method to access the component is by its parent container as (for example its TextField then)

TextField myTf = (TextField) findParentContainer().getComponentAt(0)

here instead of 0 you have to maintain correct component index from that ParentContainer.

and to compare its name you can use findParentContainer().getComponentAt(0).getName().equalsIgnoreCase(name)

E.g.:

private static Component findByName(Container root, String componentName) {
    int count = root.getComponentCount();
    for(int iter = 0 ; iter < count ; iter++) {
        Component c = root.getComponentAt(iter);
        String n = c.getName();
        if(n != null && n.equals(componentName)) {
            return c;
        }
        if(c instanceof Container) {
            c = findByName((Container)c, componentName);
            if(c != null) {
                return c;
            }
        }
    }
    return null;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to get tooltip like effects on touching on a component in codenameone

From Dev

How to get component name in swing?

From Dev

Joomla, how get component id in plugin using component name

From Dev

How to render a react component from a string name

From Dev

How to get the component's viewmodel from component's node in KnockoutJS

From Dev

How to get component properties from main component in Angular2?

From Dev

How to get component properties from main component in Angular2?

From Dev

React: How to get results from one component to another component

From Dev

Sencha Touch 2, get the name of the view from using get component

From Dev

Sencha Touch 2, get the name of the view from using get component

From Java

How to get data from function component?

From Dev

How to get component value from ActionEvent object?

From Dev

How to get property from component when testing?

From Dev

How to get component version from Joomla?

From Dev

How get data from JFrame Component Java?

From Dev

Get html class name from React component upon mounting

From Dev

Get Ember component's name

From Dev

How do I determine component with focus in a codenameone container?

From Dev

How to omit gray background color of button component in codenameone

From Dev

How is possible to change size(width and height) of the component in codenameone

From Dev

animateLayout on expanding component is not working - codenameone

From Dev

How I can get the slot name in which the component is rendered

From Dev

How to get string of x:Name property of component in Xamarin form?

From Dev

How to get current component name in Angular2

From Dev

How can I get the "Edit Component's Name" window to show when I place a component?

From Dev

How can I get the "Edit Component's Name" window to show when I place a component?

From Java

How to access the functional component's name from a React hook?

From Dev

How to render component/helper by name from instance field?

From Dev

How to add dynamic class name in button present on Child Component when clicking another button from Parent Component?

Related Related

  1. 1

    how to get tooltip like effects on touching on a component in codenameone

  2. 2

    How to get component name in swing?

  3. 3

    Joomla, how get component id in plugin using component name

  4. 4

    How to render a react component from a string name

  5. 5

    How to get the component's viewmodel from component's node in KnockoutJS

  6. 6

    How to get component properties from main component in Angular2?

  7. 7

    How to get component properties from main component in Angular2?

  8. 8

    React: How to get results from one component to another component

  9. 9

    Sencha Touch 2, get the name of the view from using get component

  10. 10

    Sencha Touch 2, get the name of the view from using get component

  11. 11

    How to get data from function component?

  12. 12

    How to get component value from ActionEvent object?

  13. 13

    How to get property from component when testing?

  14. 14

    How to get component version from Joomla?

  15. 15

    How get data from JFrame Component Java?

  16. 16

    Get html class name from React component upon mounting

  17. 17

    Get Ember component's name

  18. 18

    How do I determine component with focus in a codenameone container?

  19. 19

    How to omit gray background color of button component in codenameone

  20. 20

    How is possible to change size(width and height) of the component in codenameone

  21. 21

    animateLayout on expanding component is not working - codenameone

  22. 22

    How I can get the slot name in which the component is rendered

  23. 23

    How to get string of x:Name property of component in Xamarin form?

  24. 24

    How to get current component name in Angular2

  25. 25

    How can I get the "Edit Component's Name" window to show when I place a component?

  26. 26

    How can I get the "Edit Component's Name" window to show when I place a component?

  27. 27

    How to access the functional component's name from a React hook?

  28. 28

    How to render component/helper by name from instance field?

  29. 29

    How to add dynamic class name in button present on Child Component when clicking another button from Parent Component?

HotTag

Archive