Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Layout problems are solved by ... LayoutManagers :-) If one doesn't what you want it to do, implement the behaviour you want. </p> <p>So if the core BoxLayout simply ignores pixels due to rounding errors, subclass and make it distribute those pixels as needed. A very raw quick example:</p> <pre><code>public static class XBoxLayout extends BoxLayout { enum Strategy { NONE, STRETCH_LAST, DISTRUBUTE } private Strategy strategy; public XBoxLayout(Container target, int axis, Strategy strategy) { super(target, axis); this.strategy = strategy; } @Override public void layoutContainer(Container target) { super.layoutContainer(target); if (Strategy.NONE == strategy) return; Insets targetInsets = target.getInsets(); int targetSize = target.getWidth() - targetInsets.left - targetInsets.right; int childSum = 0; for (Component child : target.getComponents()) { childSum += child.getWidth(); } if (targetSize &gt; childSum) { int excess = targetSize - childSum; distribute(target, excess); } } private void distribute(Container target, int excess) { System.out.println("childCount/rounding excess " + target.getComponentCount() + "/" + excess); if (Strategy.STRETCH_LAST == strategy) { Component lastChild = target.getComponent(target .getComponentCount() - 1); lastChild.setSize(lastChild.getWidth() + excess, lastChild.getHeight()); } else { int firstToDistribute = target.getComponentCount() - excess; int summedOffset = 0; for(int index = firstToDistribute; index &lt; target.getComponentCount(); index++) { Component child = target.getComponent(index); Rectangle bounds = child.getBounds(); bounds.x += summedOffset++; bounds.width += 1; child.setBounds(bounds); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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