问题描述:

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.

Thanks!

网友答案:

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.

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;

Example

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.

相关阅读:
Top