0

When I was append some text dynamically to the TextArea it was wrapped correctly as follow:

TextArea

But due to requirement changed I have to add some image as bullet for (in front of the) each text. Then I used GridPane to add those text with images as follow:

GridPane

Code used to add components to GridPane:

 // Set the GridPane empty 
 gridPane.getChildren().removeAll();

 // Add image with each text
 int index = 0;
 for(String des : descriptionsList) {

     HBox btnHb = new HBox();

     ImageView passed = new ImageView();
     passed.setImage(new Image(getClass().getResourceAsStream(GuiConstant.Image.IMAGE_PASSED)));
     btnHb.getChildren().add(passed);

     Text text = new Text(des);
     btnHb.getChildren().add(text);

     gridPane.addRow(index, btnHb);
     index++;
}

Now (with GridPane) added Texts are not wrapped properly. How can I fix this issue. Thanks.

Channa
  • 4,963
  • 14
  • 65
  • 97
  • 2
    Use label instead of text. It has a wrapable method: http://docs.oracle.com/javafx/2/ui_controls/label.htm – Perneel Jul 01 '14 at 17:37
  • @Perneel Thanks for the reply. Yes when we used the Label with enabling wrapping, that will not display remaining text, Label will show only some dots for remaining text (abc dadad...). When we set value for Text controller's setWrappingWidth() method, that will show the result correctly but it override the text lines displaying on the down rows in GridPane. Even I set the rowSpan value issue was not resolved. – Channa Jul 02 '14 at 13:57
  • Hm, does it really have to be in a gridpane? If not, can you try to create a HBox for each line with the image and the label and put al those HBox objects in a VBox. Let the HBox automatically grow in size (vertical) if needed. GridPane can (in my opinion) be tricky to resize stuff. – Perneel Jul 02 '14 at 14:20
  • @Perneel Many thanks for your valuable answer. Yes as you mention it was fine with VBox but it seems have to set some Spacing to VBox. I have done upvote your comment but mistakenly undone it then unfortunately system is not allows ("You've already undone your vote; you cannot upvote it again") to upvote it again :( . So sorry about it. Have a nice time ! Thanks. – Channa Jul 03 '14 at 10:21
  • 1
    Don't worry about it, I'm glad the comment had some value to you. That's the most important thing :) – Perneel Jul 04 '14 at 09:15

1 Answers1

0

You need to set the wrappingWidth on the Text instances to be relative to the width of the GridPane. You may want to do that indirectly via the HBox instances:

btnHub.prefWidthProperty().bind(gridPane.widthProperty(); text.wrappingWidthProperty().bind(btnHub.widthProperty().subtract(passed.widthProperty().subtract(10));

I didn't actually try these changes, but they (or something very similar) should do the trick.

kylejmcintyre
  • 1,898
  • 2
  • 17
  • 19