Open QY-H00 opened 3 years ago
I was facing the same issue. Thanks for the suggestion!
@damithc Just wonder how can we possibly give credit to it if we want to reuse this piece of code?
@Cheng20010201 You could check out the module's policy on reuse here! https://nus-cs2103-ay2021s2.github.io/website/admin/appendixB-policies.html#policy-reuse
@damithc Just wonder how can we possibly give credit to it if we want to reuse this piece of code?
@Cheng20010201 You can mention the original author and point to this post as per https://nus-cs2103-ay2021s2.github.io/website/admin/appendixB-policies.html#giving-credit-for-reused-work
@Cheng20010201 You can mention the original author and point to this post as per https://nus-cs2103-ay2021s2.github.io/website/admin/appendixB-policies.html#giving-credit-for-reused-work
I mean like, I can just put comments in the fxml file in the same format as we do in java source code right? (except that the way of commeting is different)
I mean like, I can just put comments in the fxml file in the same format as we do in java source code right? (except that the way of commeting is different)
Yes 👍
Using an HBox seems to be an interesting solution! I did it in a slightly different way.
I used a javafx.scene.shape.Rectangle
as the dialog box. To print the message within the Rectangle, I wrapped both the message node and the Rectangle inside a javafx.scene.layout.StackPane
which resizes automatically so that all its children are within its boundary. However, the Rectangle does not resize automatically. Therefore, what I did was rectangleNode.heightProperty().bind(stackPaneNode.heightProperty());
so that the Rectangle's height is always equal to the height of its parent StackPane.
One benefit of this method is that you can easily replace the Rectangle with any other shape (e.g. javafx.scene.shape.Path
) without changing any other code.
A more complete Java code snippet:
Rectangle rectangleNode = new Rectangle(300.0, 20.0);
rectangleNode.setFill(Color.AQUA);
StackPane stackPaneNode = new StackPane();
stackPaneNode.getChildren().addAll(rectangleNode, messageNode);
rectangleNode.heightProperty().bind(stackPaneNode .heightProperty());
Thanks for the suggestion! However, personally, using HBox did not work for me
I managed to get things working by adding dialog.setMinHeight(Region.USE_PREF_SIZE)
in the constructor of DialogBox, as per the second answer here: https://stackoverflow.com/questions/35012518/resize-javafx-label-if-overrun
For those who use SceneBuilder, here's what worked for me:
In the DialogBox.fxml file, we can set the size of the Label element (found under Layout on the right pane) to the settings as follows. I believe this is similar to what @swayongshen has mentioned, by not fixing the height/width.
Hi firends! Recently I'm struggling with how to resize the dialog box as the amount of text changes. And I find that what we can do is Add an HBox to the outer layer of the Label. Then set the minHight of Label as -Infinity and the maxHight of HBox as -Inifinity as well. More explicitly:
I hope this will help those who are facing the same problem as me! More comments or better solutions are welcome!