border - JavaFX: Making BorderPane's Center's contents not strech -
just quick 1 since i'm inexperienced in designing apps. appreciated.
i've got following application, , it's obvious uses borderpane
layout. i've got gridpane
of 5 labels , 5 textfields
in center
region, , wanted subtle border it.
as can see, gridpane
utilizes full space allocated in center
region, , although border gets drawn nicely, goes way down bottom of center
region (red arrows). what want finish @ blue line.
i tried using grid.setprefheight(400);
, example, didn't work.
are there solutions other obvious one, add second container below gridpane
, squeeze upper container enough?
edit: reference, code creates center area gridpane
:
public gridpane addgridpanecenter() { gridpane grid = new gridpane(); grid.sethgap(10); grid.setvgap(10); grid.setpadding(new insets(0, 10, 0, 10)); sihuid = new text("sihu id:"); sihuid.setfont(font.font("inconsolata", 16)); grid.add(sihuid, 0, 1); //spans 0,1 1,1 (column-row) sihuid_tf = new textfield(); sihuid_tf.seteditable(false); grid.add(sihuid_tf, 1, 1); mac = new text("plug mac:"); mac.setfont(font.font("inconsolata", 16)); grid.add(mac, 0, 2); mac_tf = new textfield(); mac_tf.seteditable(false); grid.add(mac_tf, 1, 2); loc = new text("location:"); loc.setfont(font.font("inconsolata", 16)); grid.add(loc, 0, 3); loc_tf = new textfield(); loc_tf.seteditable(false); grid.add(loc_tf, 1, 3); appl = new text("appliance:"); appl.setfont(font.font("inconsolata", 16)); grid.add(appl, 0, 4); appl_tf = new textfield(); appl_tf.seteditable(false); grid.add(appl_tf, 1, 4); type = new text("type:"); type.setfont(font.font("inconsolata", 16)); grid.add(type, 0, 5); type_tf = new textfield(); type_tf.seteditable(false); grid.add(type_tf, 1, 5); grid.setprefheight(400); grid.setstyle( "-fx-border-color: #b8b8ba; -fx-border-width: 1;" + "-fx-border-radius: 4;" /*+ "-fx-font: " + "inconsolata" + ";" */ ); return grid;
}
after that, there's simple
gridpane grid_center = addgridpanecenter(); //center grid, contains info plugs. border_pane.setcenter(grid_center); scene scene = new scene(border_pane, 900, 700); scene.setfill(color.ghostwhite); primarystage.settitle("plugcontrol v0.1e"); primarystage.setscene(scene); primarystage.show();
i'm afraid behaviour of borderpane
design (ref):
the top , bottom children resized preferred heights , extend width of borderpane. left , right children resized preferred widths , extend length between top , bottom nodes. and center node resized fill available space in middle.
you should put gridpane
in anchorpane
or vbox
, put (anchorpane
or vbox
) in center of borderpane
.
Comments
Post a Comment