Skip to content

Commit

Permalink
Avoid IllegalArgumentException: (minimum <= value <= maximum) with sp…
Browse files Browse the repository at this point in the history
  • Loading branch information
tinevez committed Dec 9, 2024
1 parent 9200a75 commit d2e06cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ public ConfigureViewsPanel(
chckbxLimitZDepth.setFont( SMALL_FONT );
panelDrawingZDepth.add( chckbxLimitZDepth );

final SpinnerNumberModel numberModelDrawingZDepth = new SpinnerNumberModel( ds.getZDrawingDepth(), 0.5, 5000., 0.5 );
final double minZDrawingDepth = 0.5;
final double maxZDrawingDepth = 5000.;
final double zDrawingDepth = Math.min( Math.max( ds.getZDrawingDepth(), minZDrawingDepth ), maxZDrawingDepth );
final SpinnerNumberModel numberModelDrawingZDepth = new SpinnerNumberModel( zDrawingDepth, minZDrawingDepth, maxZDrawingDepth, 0.5 );
final JSpinner spinnerDrawingZDepth = new JSpinner( numberModelDrawingZDepth );
spinnerDrawingZDepth.setFont( SMALL_FONT );
panelDrawingZDepth.add( spinnerDrawingZDepth );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public SliderPanel( final String name, final BoundedValue model, final int spinn

slider = new JSlider( SwingConstants.HORIZONTAL, model.getRangeMin(), model.getRangeMax(), model.getCurrentValue() );
spinner = new JSpinner();
spinner.setModel( new SpinnerNumberModel( model.getCurrentValue(), model.getRangeMin(), model.getRangeMax(), spinnerStepSize ) );

final double min = model.getRangeMin();
final double max = model.getRangeMax();
final double val = Math.max( Math.min( model.getCurrentValue(), max ), min );
spinner.setModel( new SpinnerNumberModel( val, min, max, spinnerStepSize ) );

slider.addChangeListener( new ChangeListener()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public SliderPanelDouble(

dmin = model.getRangeMin();
dmax = model.getRangeMax();
final double val = Math.min( Math.max( model.getCurrentValue(), dmin ), dmax );

slider = new JSlider( SwingConstants.HORIZONTAL, 0, sliderLength, toSlider( model.getCurrentValue() ) );
slider = new JSlider( SwingConstants.HORIZONTAL, 0, sliderLength, toSlider( val ) );
spinner = new JSpinner();
spinner.setModel( new SpinnerNumberModel( model.getCurrentValue(), dmin, dmax, spinnerStepSize ) );
spinner.setModel( new SpinnerNumberModel( val, dmin, dmax, spinnerStepSize ) );

slider.addChangeListener( new ChangeListener()
{
Expand Down

0 comments on commit d2e06cb

Please sign in to comment.