JavaFX buttons with same size -


i have these buttons different size:

image

how can make buttons same size?

it depends on layout button located. example, if add buttons gridpane or borderpane, have specify each button width correspond variable. in following example wrap buttons inside vbox, set vbox preference width , tie buttons minimum width it:

vbox vbox = new vbox(); vbox.setprefwidth(100);  button btn1 = new button("short"); button btn2 = new button("super long button");  btn1.setminwidth(vbox.getprefwidth()); btn2.setminwidth(vbox.getprefwidth());  vbox.getchildren().addall(btn1, btn2); 

it worth mention there 2 ways specify button size. can in java code or specify in javafx .fxml file. above method example java code implementation.


you can unclamp button's maximum dimensions grow fill available space (unlike nodes, default button node has it's max size clamped it's preferred size doesn't grow fill available space). oracle tutorial on tips sizing , aligning nodes explains in more detail.

vbox vbox = new vbox();  button btn1 = new button("short"); button btn2 = new button("super long button");  btn1.setmaxwidth(double.max_value); btn2.setmaxwidth(double.max_value);  vbox.getchildren().addall(btn1, btn2); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jquery - Keeping Kendo Datepicker in min/max range -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -