java - How to grow Labels within a VBox -
i got following setup:
label errorlabel = new label("hello hans"); label warninglabel = new label("heeelllooooooooooooooooooooooooo"); vbox box = new vbox(); box.getchildren().addall(errorlabel, warninglabel); tooltip t = new tooltip(); t.setgraphic(box); t.show();
my problem is, warninglabel
, errorlabel
have different sizes. should both grow same size horizontally. don't want put specific size. size of both must whichever label needs more display whole text.
the problem is, both labels have background , can see warninglabel takes more space. need both backgrounds of label grow equally.
you can set maxwidthproperty double.max_value
in case of both label
s.
label errorlabel = new label("hello hans"); errorlabel.setstyle("-fx-background-color: red"); label warninglabel = new label("heeelllooooooooooooooooooooooooo"); warninglabel.setstyle("-fx-background-color: orange"); warninglabel.setmaxwidth(double.max_value); errorlabel.setmaxwidth(double.max_value);
the output tooltip
like:
background: making buttons same size - using vbox - example 2-1
to enable of buttons resized width of vbox pane, maximum width of each button set double.max_value constant, enables control grow without limit. alternative using maximum value constant set maximum width specific value, such 80.0.
note: important fillwidthproperty of vbox
must set true
(this property true
default):
whether or not resizable children resized fill full width of vbox or kept preferred width , aligned according alignment hpos value.
this important because:
vbox resize children (if resizable) preferred heights , uses fillwidth property determine whether resize widths fill own width or keep widths preferred (fillwidth defaults true).
so, if fillwidthproperty
set true, vbox
try resize children own width, impossible if maxwidthproperty
set preferred width of each children, that's why property must set "big-enough" number.
Comments
Post a Comment