Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the "correct" way to do this is to use the Scrollable interface:</p> <pre><code>public class ScrollPaneWidthTrackingPanel extends JPanel implements Scrollable { private static final long serialVersionUID = 1L; public ScrollPaneWidthTrackingPanel(LayoutManager layoutManager) { super(layoutManager); } public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { return Math.max(visibleRect.height * 9 / 10, 1); } public boolean getScrollableTracksViewportHeight() { return false; } public boolean getScrollableTracksViewportWidth() { return true; } public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { return Math.max(visibleRect.height / 10, 1); } } </code></pre> <p>Two lines of your code then have to change to:</p> <pre><code>final ScrollPaneWidthTrackingPanel bigPane = new ScrollPaneWidthTrackingPanel(new GridLayout(0, 1)); frame.setContentPane(new JScrollPane(bigPane)); </code></pre> <p>And the components should always fill the entire width of the JScrollPane, whatever the size of the frame. This change has a side effect that the components will now not fill the height of the JScrollPane. To solve that add the following code to the top of the getScrollableTracksViewportHeight method:</p> <pre><code>if (getParent() instanceof JViewport) { JViewport viewport = (JViewport) getParent(); return component.getPreferredSize().height &lt; viewport.getHeight(); } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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