N
N
Neonoviiwolf2019-06-15 03:13:24
Java
Neonoviiwolf, 2019-06-15 03:13:24

JavaFx how to get parameters from controller?

Good
There is a VBox, the user adds a Node containing an Image to it. Those. children is dynamically populated in VBox. At some point, I need to know how to get data from the control of these Node, how to do it?
What I'm doing is looping through the children of the VBox, getting links to the children, but how do I get data from the controller? (Node contains an image, I need to get the path to it)
example but doesn't work

for (int i = 0; view.getVBox_image().getChildren().size() > i; ++i) {

                V_ItemImageIcon itemImage = (V_ItemImageIcon) view.getVBox_image().getChildren().get(i);

                image.add(itemImage.getFileImage());
            }

Error:(174, 101) java: incompatible types: javafx.scene.Node cannot be converted to com.view.vItemImageIcon.v.V_ItemImageIcon

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergey, 2019-06-15
kuzmin @sergueik

Neonoviiwolf
tried to give in xmlfx:id
in the code to create a variable in the controller class

@FXML
    private Image dialogImage;

and just call its method
if (dialogImage != null) {
        System.err.println(String.format("The image url: %s",
            dialogImage.impl_getUrl()));
      }

seems to give the correct answer something like:
a for casting Node in e.g. ImageView set fx:id to Label
<Label fx:id="dialogImageLabel">
          <graphic>
            <ImageView fx:id="dialogImageView" fitHeight="128" fitWidth="128" pickOnBounds="true" preserveRatio="true">
              <image>
                <Image fx:id="dialogImage" url="@watchglass.png"/>
              </image>
            </ImageView>
          </graphic>
      </Label>

and
for (int i = 0; i != dialogImageLabel.getChildrenUnmodifiable()
                .size(); i++) {
Node itemNode = dialogImageLabel.getChildrenUnmodifiable().get(i);
      if (itemNode.getClass().getName().equals("javafx.scene.image.ImageView")) {
        ImageView imageView = (ImageView) itemNode;
                System.err.println(String.format("The child image url: %s",
                    imageView.getImage().impl_getUrl()));
        }

}
the same
The child image url: file:/<путь к проекту>/src/main/resources/картина.png

N
Neonoviiwolf, 2019-06-15
@Neonoviiwolf

not quite the same, probably unsuccessfully explained
VBox - a container, the client adds Pane to it, which in turn contains some objects, including image. I need to somehow get data from the Pane controller, more precisely a link to an Image
5d0497e22537c206935030.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question