@@ -32,18 +32,23 @@ public class ChatMessageComponent extends HBox {
32
32
private final ObjectProperty <ChatMessage > chatMessage = new SimpleObjectProperty <>();
33
33
private final ObjectProperty <Consumer <ChatMessageComponent >> onDelete = new SimpleObjectProperty <>();
34
34
35
- @ FXML private HBox wrapperHBox ;
36
- @ FXML private VBox vBox ;
37
- @ FXML private Label sourceLabel ;
38
- @ FXML private Pane markdownContentPane ;
39
- @ FXML private VBox buttonsVBox ;
35
+ @ FXML
36
+ private HBox wrapperHBox ;
37
+ @ FXML
38
+ private VBox vBox ;
39
+ @ FXML
40
+ private Label sourceLabel ;
41
+ @ FXML
42
+ private Pane markdownContentPane ;
43
+ @ FXML
44
+ private VBox buttonsVBox ;
40
45
41
46
private MarkdownTextFlow markdownTextFlow ;
42
47
43
48
public ChatMessageComponent () {
44
49
ViewLoader .view (this )
45
- .root (this )
46
- .load ();
50
+ .root (this )
51
+ .load ();
47
52
48
53
chatMessage .addListener ((_ , _ , newValue ) -> {
49
54
if (newValue != null ) {
@@ -107,9 +112,14 @@ private void initialize() {
107
112
markdownContentPane .getChildren ().add (markdownTextFlow );
108
113
markdownContentPane .minHeightProperty ().bind (markdownTextFlow .heightProperty ());
109
114
markdownContentPane .prefHeightProperty ().bind (markdownTextFlow .heightProperty ());
110
- NumberBinding maxUsableWidth = Bindings .createDoubleBinding (() -> getScene ().getWidth () - 20 , sceneProperty (), getScene ().widthProperty ());
111
- markdownTextFlow .maxWidthProperty ().bind (maxUsableWidth );
112
- wrapperHBox .maxWidthProperty ().bind (maxUsableWidth );
115
+ this .sceneProperty ().addListener ((_ , _ , scene ) -> {
116
+ if (scene == null ) {
117
+ return ;
118
+ }
119
+ NumberBinding maxUsableWidth = Bindings .createDoubleBinding (() -> getScene ().getWidth () - 20 , sceneProperty (), getScene ().widthProperty ());
120
+ markdownTextFlow .maxWidthProperty ().bind (maxUsableWidth );
121
+ wrapperHBox .maxWidthProperty ().bind (maxUsableWidth );
122
+ });
113
123
setMaxWidth (Double .MAX_VALUE );
114
124
HBox .setHgrow (this , Priority .ALWAYS );
115
125
}
0 commit comments