fjtsai / geoviz

Automatically exported from code.google.com/p/geoviz
0 stars 0 forks source link

RangeSlider/MultiSlider cause exceptions with JDK7 #80

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Since JDK 7 is fast coming down the track with a number of very desirable 
features I have been trying to convert code to take advantage of some of the 
features.

Unfortunately openJDK have made changes in JSlider and when I built the 
RangeSlider test the following exception is thrown:

Exception in thread "main" java.lang.NullPointerException
        at WindowsIO.MultiSlider.getCurrentThumbIndex(MultiSlider.java:274)
        at WindowsIO.MultiSlider.setModel(MultiSlider.java:320)
        at javax.swing.JSlider.<init>(JSlider.java:273)
        at javax.swing.JSlider.<init>(JSlider.java:181)
        at WindowsIO.MultiSlider.<init>(MultiSlider.java:93)
        at WindowsIO.MultiSlider.<init>(MultiSlider.java:121)
        at WindowsIO.RangeSlider.initialize(RangeSlider.java:203)
        at WindowsIO.RangeSlider.setRangeTitle(RangeSlider.java:696)
        at WindowsIO.RangeSlider.main(RangeSlider.java:870)

It would appear that the way UI is handled is now different.

Although you are focused on JDK 6 I believe a lot of developers are trying to 
move to 7 and will encounter this problem.

Original issue reported on code.google.com by rudi.die...@gmail.com on 1 Dec 2010 at 5:23

GoogleCodeExporter commented 8 years ago
Rudi, thank you for the report. We want to support JDK7 so this is an important 
bug. I'll look into it when I have time, which will hopefully be soon (during 
Dec.). If you learn any more about this bug, please do let me know. 

Original comment by frank.hardisty on 1 Dec 2010 at 7:44

GoogleCodeExporter commented 8 years ago
I am trying various things debugging my way through JDK 7 - but they seem to 
have made a bunch of changes to the whole slider and the corresponding UI 
handling.

Original comment by rudi.die...@gmail.com on 1 Dec 2010 at 9:55

GoogleCodeExporter commented 8 years ago
So - here is where things go south ---

In JSlider...

JDK 6

    public JSlider(int orientation, int min, int max, int value) 
    {
        checkOrientation(orientation);
        this.orientation = orientation;
        sliderModel = new DefaultBoundedRangeModel(value, 0, min, max);
        sliderModel.addChangeListener(changeListener);
        updateUI();
    }

JDK 7

    public JSlider(int orientation, int min, int max, int value)
    {
        checkOrientation(orientation);
        this.orientation = orientation;
        setModel(new DefaultBoundedRangeModel(value, 0, min, max));
        updateUI();
    }

When the call in JDK 7 is made the overridden setModel in MultiSlider assumes a 
UI is in existence but the call to updateUI has not yet been made.

So much for now. Hope this helps you. Am still digging.

Original comment by rudi.die...@gmail.com on 1 Dec 2010 at 10:39

GoogleCodeExporter commented 8 years ago
I have a fix - will provide shortly once I clean it up - but I have it running 
under JDK 7 - it is a bit of a kludge - but you can at least see what I did.

Original comment by rudi.die...@gmail.com on 1 Dec 2010 at 10:57

GoogleCodeExporter commented 8 years ago
The changes are to two methods in MultiSlider.java.
By catching the exceptions that are thrown when trying to use the model before 
it is in place everything ends up working. (Do I get a prize?)

    public int getValue() {
      try
       {
                return getValueAt(getCurrentThumbIndex());

       }
      catch (Exception e)
       {
        return 0;
       }
    }

 public void setModel(BoundedRangeModel newModel)
   {

    try
     {
      setModelAt(getCurrentThumbIndex(), newModel);

     }
    catch (Exception e)
     {
      this.sliderModel = newModel;
     }
   }

Original comment by rudi.die...@gmail.com on 1 Dec 2010 at 11:10

GoogleCodeExporter commented 8 years ago
Although the above changes to MultiSlider make it work, I consider this to be a 
bug in JDK 7 since it breaks existing code.

Original comment by rudi.die...@gmail.com on 2 Dec 2010 at 12:18

GoogleCodeExporter commented 8 years ago
Hi, the fix by rudi doesn't work for me. I get exactly the same error at the 
console. There are something more to change?? 

Original comment by PepLopez...@gmail.com on 27 Feb 2013 at 4:11