5

I'm new using Codename One. I'm doing an app which have a Form, that has a Tab component with 14 tabs inside, every tab has a gridlayout with 42 buttons, and I want to change a property in one button. The problem is that I don't know how to reach that button.

tabG.getContentPane().components.get(index)

tabG is the tab component, and I can reach the tab that I need, but after that I don't know how to reach the button index I want to change.

I tried

tabG.getContentPane().components.get(index).components.get(indexbutton)

But even can't compile this code.

enter image description here

I'll apprecciate any help.

  • 1
    How did you create the components within the tab? In the creation code you need to prepare a strategy to find the component later. – Shai Almog Jan 23 '20 at 02:09

1 Answers1

1

When you create the tab you need to prepare information to find the component later. E.g. if all tabs derive from the same class then just do something like:

MyBaseContainer cnt = (MyBaseContainer)tabs.getTabComponentAt(index);
Button theButtonINeed cnt.getMyImportantButton();

If this is more complicated you can use setName() or putClientProperty to prepare hints for you during form construction.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks [Shai Almog](https://stackoverflow.com/users/756809/shai-almog). Now I realize, that the answer was to easy. But now, exists something like html id, and when is needed in javascript or jquery you can access with getElementById(id) or $("#id")? – Alejandro Vargas Jan 23 '20 at 20:05
  • 2
    We have that: https://www.codenameone.com/blog/jquery-css-style-selectors-for-cn1.html – Shai Almog Jan 24 '20 at 06:17