From d2e06cbbb6db4080dcbaa9cbb7953a5aed3c02f1 Mon Sep 17 00:00:00 2001 From: Jean-Yves Tinevez Date: Mon, 9 Dec 2024 15:57:43 +0100 Subject: [PATCH] Avoid IllegalArgumentException: (minimum <= value <= maximum) with spinner models. See https://forum.image.sc/t/trackmate-not-opening-on-mac/105975 --- .../trackmate/gui/components/ConfigureViewsPanel.java | 5 ++++- .../plugin/trackmate/gui/displaysettings/SliderPanel.java | 6 +++++- .../trackmate/gui/displaysettings/SliderPanelDouble.java | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/fiji/plugin/trackmate/gui/components/ConfigureViewsPanel.java b/src/main/java/fiji/plugin/trackmate/gui/components/ConfigureViewsPanel.java index 57a48197d..fc7302fa1 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/components/ConfigureViewsPanel.java +++ b/src/main/java/fiji/plugin/trackmate/gui/components/ConfigureViewsPanel.java @@ -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 ); diff --git a/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanel.java b/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanel.java index 1b00641c2..3af77b6e7 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanel.java +++ b/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanel.java @@ -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() { diff --git a/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanelDouble.java b/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanelDouble.java index 9e49e5162..e91d751c5 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanelDouble.java +++ b/src/main/java/fiji/plugin/trackmate/gui/displaysettings/SliderPanelDouble.java @@ -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() {