Как рассчитать расстояние от базового уровня одной метки до вершины текста в другой этикетке в Javafx?JAVA

Программисты JAVA общаются здесь
Anonymous
Как рассчитать расстояние от базового уровня одной метки до вершины текста в другой этикетке в Javafx?

Сообщение Anonymous »

У меня есть две метки, размещенные один ниже другой. Обе этикетки содержат текст в прописных буквах. Мне нужно рассчитать точное расстояние от базовой линии верхней метки до верхней части текста в нижней метке. Это мой код: < /p>

Код: Выделить всё

public class TestFx extends Application {

@Override
public void start(Stage primaryStage) {
var text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var font = Font.font("System", 24);
Label topLabel = new Label(text);
topLabel.setFont(font);
topLabel.setStyle("-fx-background-color: yellow");

Label bottomLabel = new Label(text);
bottomLabel.setFont(font);
bottomLabel.setStyle("-fx-background-color: orange");

// Calculate the distance from the baseline of topLabel
// to the top of the bottomLabel

//double baselineToTop = ???; // What should go here?

VBox root = new VBox(topLabel, bottomLabel);
Scene scene = new Scene(root, 600, 200);
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}

Может ли кто -нибудь сказать, как это сделать?

Подробнее здесь: https://stackoverflow.com/questions/796 ... t-in-anoth

Вернуться в «JAVA»