Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resize JavaFX ScrollPane content to fit current size
    primarykey
    data
    text
    <p>I have a <code>BorderPane</code> with a <code>ScrollPane</code> as the center element. It resizes automatically to fill the screen. Inside the <code>ScrollPane</code> is a <code>HBox</code> that has no content but is a drag-and-drop target. Therefore I want it to fill its parent <code>ScrollPane</code>.</p> <p>What is the preferred way to do this?</p> <p>What I have tried so far is overriding the <code>ScrollPane.resize(...)</code> method to resize the <code>HBox</code> but it seems rather complicated and unorthodox.</p> <p>edit: To add some useful code to this, this is how I can workaround the problem, but I believe there has to be some better way to do this:</p> <pre><code>@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); } </code></pre> <p>Code partly taken from here: <a href="https://stackoverflow.com/questions/12678317/how-to-access-the-scrollbars-of-a-scrollpane">How to access the Scrollbars of a ScrollPane</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload