I want to make the height of my TextField much bigger (it should take up almost half the screen). I am using this code:
concordText = new TextField("");
concordText.setPrefHeight(400);
concordText.setPrefWidth(80);
This does increase the size of the TextField, but the text starts from the middle (as shown in the picture). How do I make it start from the beginning of the text?
Since a TextField is only meant for a single line of text, you want to use a TextArea instead.
In order to make the TextArea extend to vertically to fill its available space, wrap it in a VBox and set the VGrow priority accordingly:
TextArea textArea = new TextArea();
VBox.setVgrow(textArea, Priority.ALWAYS);
Related
Trying to align children(labels) of 2 different HBoxes, which was created by the same method:
public HBox addHBox() {
HBox hbox = new HBox(10);
hbox.setLayoutX(10);
hbox.setPrefWidth(Pane.getWidth());
hbox.setPrefHeight(Pane.getHeight());
return hbox;
}
The LayoutY is different, and changed after the creation of each HBox.
Thus, I want to accompish that added child[i] of the HBox1, would be right below child[i] of the HBox2.
Note: the size of the children should not matter!
(this is what bothers me)
I tried
hbox2.setMinWidth(hbox1.getMinWidth());
and
hbox2.setPrefWidth(hbox1.getPrefWidth());
and
hbox2.setMaxWidth(hbox1.getMaxWidth());
Nothing seems to help. Any ideas?
P.S. I know that i can use gridPane, but it's not in this case
Your HBox only classifies your Nodes one side of the other horizontally, and in your case I suppose that you use a Text control to display your String, I don't say that it is a bad idea but I think that the width of your Node(Text) depends on the length of the string which gives an unpredictable and disorderly display, so why not use a Label, the advantage with this control is that you can define the Width of the background what Will give your String a limit and allow an ordered display !
Okay, after additional research AND help of the community:
1.Definately should use gridPane.
2.Or change the layoutX of each label in HBox2 to fit layoutX of label from HBox1.
How can I center the text of a Label in javafx ? In the .css stylesheet or directly in the fxml.
I tried Label { -fx-text-alignment: center;} in the .css but it does not work. Even in the scene builder it does not work.
You basically have two choices:
Use a layout pane that can center the label, and let the label be its "preferred size" (i.e. just big enough to hold the text), or
Make the label fill the entire width of its container, and set its alignment property to center.
You said in the comments that you're using an AnchorPane as the label's parent. This generally isn't usually a particularly good choice for a layout pane (essentially you have to hardcode the bounds of each control), and you can't center things in it (not without a large amount of work, anyway). So with an anchor pane as parent, you are reduced to choice 2:
label.setMaxWidth(Double.MAX_VALUE);
AnchorPane.setLeftAnchor(label, 0.0);
AnchorPane.setRightAnchor(label, 0.0);
label.setAlignment(Pos.CENTER);
Obviously, all that can be set in FXML too.
In general, though, I would recommend using a more appropriate layout pane and setting the appropriate properties on that layout pane to center the label.
I have Situation I have two VBox named(title_Box,content_Box) I am putting both VBox inside my Panel. the content of content_Box is not same its vary . so how I can put my title_Box space according to content_Box.
following is I want to achieve.
title1
content1....
content2....
title2
content1...
title3
content1..
content2..
content3...
so how I can get/set spacing to title_box according to content_Box...
is there any way ..
because I search a lot but everywhere set spacing constant like
VBox vb=new Vbox(10);
So how I can set it according to another container(VBox) Height.
Update
Make title_Box and content_Box children of a parent VBox container. Then set the vertical grow priority for for content_Box to Priority.ALWAYS. This will make sure that the parent vbox will use the priority to allocate additional space if it is resized larger than it's preferred height.
VBox.setVgrow(content_Box, Priority.ALWAYS);
i've got following problems.
How, in FXML, put for ex. 3 TitlePanes into ScrollPane, in such way, that when i open all 3 TitlePanes, the vertical scroll will appear, but when i have for ex. 1 open it disappear? (fit ScrollPane height to it's dynamicaly changing content)
How, in FXML, put TilePane into TitlePane, that TitlePane will fit to it content? For ex. i put 4 Buttons into TilePane. At begining it's 2x2. When i reduce width, it change into 4x1, TilePane heigth grow, but TitlePane doesnt grow with it, and not all Buttons are visible. How to connect TilePane size with its container TitlePane size?
I'll be appriciate for any help.
If you are using FXML, make sure that you do not set the preferred height of the controls you want to resize, they should be set to COMPUTED. With this set, a collapsed TitledPane will only take up the size of it's title.
I have a problem in flex scroll bars. I have a mxml component based on canvas. Inside that I have used a VBox for my form. Above that Vbox I have another canvas just for title.
My form gets longer than normal screen size when the grid inside that is filled with more data. In that case I want a vertical scroll bar just for Vbox in which my form is located. But the whole canvas is getting scrollbar including title canvas. how to solve this problem.
I set vertical scrollbar policy of main canvas to off and inside Vbox's VerticalScrollbarPolicy to on. but that's not working. It is not overriding the property of parent container.
Thanks.
Keep your Form inside a Canvas inside the parent canvas instead of VBox. VBox and HBox are set to grow automatically in the parent container, so if your form grows, your corresponding VBox will grow as well.
You want to overload the "updateDisplayList" function for your parent canvas, and force the height of your form Vbox to be canvasHeight-titleHeight (including padding, space, etc...) so that the VBox never grows larger than the screen. This will solve your problem. Just make sure you check for the existence of the VBox as sometimes the updateDisplayList will be called before it has been instantiated.
Had the same problem myself and decided to take the easy route.
Have the following
App->vbox->[vbox + hbox]
components are dynamically being added to last vbox. Wanted hbox to stay on screen and have scrollbars only in vbox above it(2nd vbox).
Was experiencing the same problem. All containers had scroll policy=off except for last vbox, but when dynamically adding components, when the components filled the vbox > 100%, the outer vbox would start to scroll.
Resolution was simple once I went back to the documentation.
Set scroll policy - horizontal and vert on app and first vbox to off, and also added autoLayout=false. This causes the engine to not resize the components after initialization, ie, they are static sized.
Once I added this property, no more scrollbars except for the inner vbox.
Tada!