53

中心要素としてaBorderPaneがあります。ScrollPane画面いっぱいに自動的にサイズ変更されます。の内部にScrollPaneは、HBoxコンテンツはありませんが、ドラッグ アンド ドロップ ターゲットの があります。したがって、その親を埋める必要がありScrollPaneます。

これを行うための好ましい方法は何ですか?

私がこれまでに試したことはScrollPane.resize(...)、サイズを変更する方法をオーバーライドするHBoxことですが、かなり複雑で非正統的なようです。

編集:これに便利なコードを追加するには、これが問題を回避する方法ですが、これを行うにはもっと良い方法が必要だと思います:

@Override
public void resize(double width, double height) {
    super.resize(width, height);

    double scrollBarHeight = 2;
    double scrollBarWidth = 2;

    for (final Node node : lookupAll(".scroll-bar")) {
        if (node instanceof ScrollBar) {
            ScrollBar sb = (ScrollBar) node;
            if (sb.getOrientation() == Orientation.HORIZONTAL) {
                System.out.println("horizontal scrollbar visible = " + sb.isVisible());
                System.out.println("width = " + sb.getWidth());
                System.out.println("height = " + sb.getHeight());
                if(sb.isVisible()){
                    scrollBarHeight = sb.getHeight();
                }
            }
            if (sb.getOrientation() == Orientation.VERTICAL) {
                System.out.println("vertical scrollbar visible = " + sb.isVisible());
                System.out.println("width = " + sb.getWidth());
                System.out.println("height = " + sb.getHeight());
                if(sb.isVisible()){
                    scrollBarWidth = sb.getWidth();
                }
            }
        }
    }

    hBox.setPrefSize(width-scrollBarWidth, height-scrollBarHeight);
}

コードの一部はここから抜粋: How to access the Scrollbars of a ScrollPane

4

2 に答える 2

30

またはを介し​​てfitToHeightまたはfitToWidth属性を設定します。XMLCSS

FXML:

<ScrollPane fx:id="myScrollPane" fitToHeight="true" fitToWidth="true" />

CSS:

.my-scroll-pane {
    -fx-fit-to-height: true;
    -fx-fit-to-width: true;
}
于 2015-04-07T12:11:06.733 に答える