简体   繁体   English

javafx:为GridPane中的标签设置不同的节点方向

[英]javafx: set different Node Orientation for labels in GridPane

I have a GridPane and I want one label to span from left to right , while the other label to span from right to left . 我有一个GridPane,我希望一个标签从左到右 ,而另一个标签从右到左 However, I just cannot get this working. 但是,我只是无法正常工作。 I can set node orientation for the GridPane itself but not for the individual labels. 我可以为GridPane本身设置节点方向,但不能为单个标签设置节点方向。

This is what I have so far: 这是我到目前为止的内容:

GridPane gridPane = new GridPane();
...
// upper left corner of grid pane
Label label1 = new Label("left to right");
label1.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
gridPane.add(label1, 0, 0,7,1);

// bottom right corner of grid pane
Label label2 = new Label("right to left");
label2.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
gridPane.add(label2, 2, 9,8,1);

UPDATE: Since GridPane default node orientation is from left to right, label1 is actually fine. 更新:由于GridPane默认节点方向是从左到右,所以label1实际上很好。 Problem is with my label2. 问题出在我的标签上。 I want it to span from right to left such that regardless of the length of the text, it always starts at the bottom rightmost corner. 我希望它从右到左跨度,以便无论文本的长度如何,它总是从最右下角开始。

An ideal example (3 X 10) would be: 一个理想的示例(3 X 10)是:

|Label1          |
|                |
|          Label2|

Ideally, if Label2 span the grids from right to left and if the length of the text in the label increases, it would look like this: 理想情况下,如果Label2从右到左跨越网格,并且标签中文本的长度增加,则看起来像这样:

|Label1          |
|                |
|      Label2Long|

But right now, what I am getting is this: 但是现在,我得到的是:

|Label1          |
|                |
|  Label2Long    |     <- I want to get rid of the space between the label and the right border

nodeOrientation has nothing to do with alignment, which is what you really want here. nodeOrientation与对齐无关,这是您真正想要的。

I think you want 我想你要

GridPane.setHalignment(label2, HPos.RIGHT);

The Javadocs for GridPane describe how to use all these settings in a lot of detail. GridPane的Javadocs GridPane描述了如何使用所有这些设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM