#2397 Widget to fwt::Text

Francesc Clopes Mon 2 Mar 2015

Hi, I am developing a fwt::GridPane that contains fwt::Text and fwt::Label widgets, constructed dynamically in code.

In the project I need to catch the text value of all fwt::Text that contains the GridPane.

Now I have a list of widgets and know when a widget is a instance of fwt::Text, but I don't know how to catch the widget text value or how to cast the widget to fwt::Text.

My code: private Void gridToText(GridPane gridToData){

listChilds := gridToData.children
sizeListChilds := gridToData.children.size 
num := 0
while(num < sizeListChilds )
{
  if( listChilds[num] is fwt::Text ){
    //Catch text value
  }
  num++
}

}

There is a way to cast the Widget to fwt::Text?

SlimerDude Mon 2 Mar 2015

An explicit cast is the same as in Java and looks like this:

private Void gridToText(GridPane gridToData){

  listChilds := gridToData.children
  sizeListChilds := gridToData.children.size 
  num := 0
  while(num < sizeListChilds )
  {
    if( listChilds[num] is fwt::Text ){
      
      // cast the child to fwt::Text
      text := (fwt::Text) listChilds[num]

      // grab the text value
      textValue := text.text
      
      // print text value
      echo(text)
    }
    num++
  }
}

Or you could use a dynamic method invocation, which would work but is less appealing:

// grab the text value
textValue := listChilds[num]->text
      
// print text value
echo(text)

Francesc Clopes Mon 2 Mar 2015

Thanks, for the reply. It works perfect.

Login or Signup to reply.