以下のConstrainedGridPaneクラスはこれを行うのに役立ちます。私はGridPaneを使用して考えられていなかったが、今振り返ってみると、それは当然の選択だ
public class LabelPane extends ConstrainedGridPane() {
public LabelPane() {
// ... setup you labels
// hgap=0 - 1 column using 100%
super.fixColumnSizes(0,100);
// vgap=5 - 4 columns using 25% each ...
super.fixRowSizes(5, 25,25,25,25);
}
}
ConstrainedGridPaneソースコード
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.RowConstraints;
/**
* a GridPane with Column and RowConstraints
* @author wf
*
*/
public class ConstrainedGridPane extends GridPane {
/**
* fix the columnSizes to the given column Width
* @param colWidths
*/
public void fixColumnSizes(int hGap,int... colWidths) {
this.setHgap(hGap);
// Setting columns size in percent
for (int colWidth : colWidths) {
ColumnConstraints column = new ColumnConstraints();
column.setPercentWidth(colWidth);
getColumnConstraints().add(column);
}
}
/**
* fix the rowSizes to the given rowHeights
* @param rowHeights
*/
public void fixRowSizes(int vGap,int... rowHeight) {
this.setVgap(vGap);
for (int rowWidth : rowHeight) {
RowConstraints rowc = new RowConstraints();
rowc.setPercentHeight(rowWidth);
getRowConstraints().add(rowc);
}
// grid.setPrefSize(WINDOW_WIDTH, WINDOW_HEIGHT); // Default width and
// height
this.setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
}
}
:あなたはこのようにそれを拡張したいあなたの4ラベルの場合 。ご協力いただきありがとうございます。 –
Swingを使用している場合は、JavaFXのSwingの 'GridBagLayout'に相当する位置付けを最大限に制御できるレイアウトペインです。 –