I have been trying all day to create a JavaFX UI that will let me display short messages the way they do on a texting client. I feel like the way to go would be with a GridPane, but I can't figure out how to set each box of the GridPane. Can someone please explain that or if you have a better solution I'd be glad to hear it.
我一整天都在尝试创建一个JavaFX UI,让我可以像在短信客户端上那样显示短消息。我觉得可以采用GridPane,但我无法弄清楚如何设置GridPane的每个框。有人可以解释一下,或者如果你有更好的解决方案,我会很高兴听到它。
Thanks!
1 个解决方案
#1
1
Using a GridPane is perfectly possible, the important thing for a smartphone-message like style is to make sure you have <ColumnConstraints halignment="LEFT" />
for the left column and "RIGHT" for the right column.
使用GridPane是完全可能的,对于像样式这样的智能手机消息来说,重要的是确保左列的
Labels can be used to display a message, with (for example)
标签可用于显示消息,例如()
-fx-padding: 10px;
-
-fx-background-color
for different types of messages/different users -fx-background-radius: 5px;
-fx-background-color用于不同类型的消息/不同用户
In Java, you can then simply add the Labels using GridPane.add(Node, int, int) with the first int parameter being 0 or 1 to determine the column and the second int being the number of the message, i.e. you can use a counter that is incremented by 1 for each message added.
在Java中,您可以使用GridPane.add(Node,int,int)添加标签,第一个int参数为0或1以确定列,第二个int为消息编号,即您可以使用对于添加的每条消息,计数器增加1。
#1
1
Using a GridPane is perfectly possible, the important thing for a smartphone-message like style is to make sure you have <ColumnConstraints halignment="LEFT" />
for the left column and "RIGHT" for the right column.
使用GridPane是完全可能的,对于像样式这样的智能手机消息来说,重要的是确保左列的
Labels can be used to display a message, with (for example)
标签可用于显示消息,例如()
-fx-padding: 10px;
-
-fx-background-color
for different types of messages/different users -fx-background-radius: 5px;
-fx-background-color用于不同类型的消息/不同用户
In Java, you can then simply add the Labels using GridPane.add(Node, int, int) with the first int parameter being 0 or 1 to determine the column and the second int being the number of the message, i.e. you can use a counter that is incremented by 1 for each message added.
在Java中,您可以使用GridPane.add(Node,int,int)添加标签,第一个int参数为0或1以确定列,第二个int为消息编号,即您可以使用对于添加的每条消息,计数器增加1。