Wie man label.getWidth() in javafx

immer wenn ich versuche die Breite eines Arrays in Java es gibt nur 0 und ich weiß nicht, warum. Kann jemand mir erklären, wie es richtig gemacht wird?

                Label label = new Label();
                label.setFont(Font.font(label.getFont().getFamily(), 8));
                label.setText(""
                        + a[i][j].getList().getFirst().getLength()
                        + " mal "
                        + intToColor(a[i][j].getList().getFirst()
                                .getColor()));
                label.relocate((x1 + x2) / 2 - label.getWidth() / 2, (y1 + y2) / 2);
                label.idProperty().set("trackName");
                label.setTextFill(Color.web("GREEN"));
                field.getChildren().addAll(path, label);
                System.out.println(label.getLayoutBounds().getWidth());
                System.out.println(label.getWidth());//... also i tested a lot of different getters but i couldn't get the label width (same problem with height)

Hoffe, du hast eine Idee, was ich zu tun habe.

@tomsontom

Tat dies:

                label.prefWidth(-1);
                label.prefHeight(-1);
                label.impl_processCSS(true);
//                 label.resizeRelocate(x, y, width, height);
                System.out.println(label.getWidth());

aber es hat nicht funktioniert, erklären Sie mir genauer, was ich tun muss?

InformationsquelleAutor baxbear | 2014-01-12
Schreibe einen Kommentar