Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"nichts einfacher als das" - dachte ... (insert name :-)</p> <p>Basically, all such enhanced functionality must be implemented in the model: for JSlider, that's a BoundedRangeModel. Implement/extend and enforce its value to respect the "combined" max. Something like </p> <pre><code>public static class LimitedBoundedRangeModel extends DefaultBoundedRangeModel { BoundedRangeModel limit; public LimitedBoundedRangeModel(BoundedRangeModel limit) { this.limit = limit; } /** * @inherited &lt;p&gt; */ @Override public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) { if (limit != null) { int combined = newValue + limit.getValue(); if (combined &gt; newMax) { newValue = newMax - limit.getValue(); } } super.setRangeProperties(newValue, newExtent, newMin, newMax, adjusting); } } // use LimitedBoundedRangeModel firstModel = new LimitedBoundedRangeModel(null); LimitedBoundedRangeModel secondModel = new LimitedBoundedRangeModel(firstModel); firstModel.limit= secondModel; JSlider first = new JSlider(firstModel); JSlider second = new JSlider(secondModel); </code></pre> <p>While simple (two dependents only) and crude (direct bidirectional coupling) and as such not really usable out in the wild, it should at least work ... but doesn't - one of those surprises which hit me from time to time ;-) The visual problem is the thumb-position:</p> <ul> <li>the combined max is respected when clicking to the right of the thumb: the thumb never moves over the threshhold</li> <li>when dragging, the thumb can be moved everywhere which might be expected, as the ui isn't aware of the model tweak - it knows only the "local" max</li> <li>on drag-end, the thumb remains at that invalid position.. which smells like a bug as now the thumb is out-off synch with the model </li> </ul> <p>The reason for this misbehaviour is that the changeListener in Handler: it doesn't recalculate its thumb position when dragging (which is okay). The subtle bug is, that the internal dragging flag is only reset <em>after</em> the model's adjusting property is reset, so missing the very last notification about the final value ...</p> <p>Hack around is to invoke the firing of an additional changeEvent, if the adjusting flag changes from true to false </p> <pre><code> boolean invoke = (adjusting != getValueIsAdjusting()) &amp;&amp; !adjusting; super.setRangeProperties(newValue, newExtent, newMin, newMax, adjusting); if (invoke) { SwingUtilities.invokeLater(new Runnable() { public void run() { fireStateChanged(); } }); } </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