Results 1 to 14 of 14
  1. #1
    nishchal6 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Help with IllegalArgumentException: invalid range properties

    Can anyone please help me, I am getting this error
    Exception in thread "main" java.lang.IllegalArgumentException: invalid range properties
    at javax.swing.DefaultBoundedRangeModel.<init>(Defaul tBoundedRangeModel.java:102)
    at javax.swing.JScrollBar.<init>(JScrollBar.java:158)
    at gui.MainWindow.<init>(MainWindow.java:333)
    at communication.Provider.main(Provider.java:41)

    and the error is in the first line of the following code--->
    ts = new JScrollBar(JScrollBar.HORIZONTAL, ClientCount.returncount(), 1, 0, ClientCount.returncount());
    ts.setUnitIncrement(ClientCount.returncount()-1);
    ts.setBlockIncrement(1);
    GridBagConstraints gbc_scrollBar = new GridBagConstraints();
    gbc_scrollBar.fill = GridBagConstraints.BOTH;
    gbc_scrollBar.gridwidth = gbc_scrollBar.REMAINDER;
    gbc_scrollBar.insets = new Insets(0, 0, 0, 0);
    gbc_scrollBar.gridx = 0;
    gbc_scrollBar.gridy = 5;
    contentPane.add(ts, gbc_scrollBar);
    ts.addAdjustmentListener(this);

    I want to set the minimum position of the scroll bar as 0 and maximum value is ClientCount.returncount() which I get from this function.

    and I implemented the Adjustmentevent as this:-
    public void adjustmentValueChanged(AdjustmentEvent e) {
    // TODO Auto-generated method stub
    this.ax = e.getValue();
    this.link();
    repaint();
    }
    The current value which I am getting from e.getvalue() is of type Integer and I am putting this in variable ax.
    So, do I have to convert this value or anything else.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default Re: Problems with values that come from the JSlider

    Exception in thread "main" java.lang.IllegalArgumentException: invalid range properties
    at javax.swing.DefaultBoundedRangeModel.<init>(Defaul tBoundedRangeModel.java:102)
    at javax.swing.JScrollBar.<init>(JScrollBar.java:158)
    at gui.MainWindow.<init>(MainWindow.java:333)
    what are the values of the range you are trying to set at line 333?
    Use a println statement to print them out.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    nishchal6 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Re: Problems with values that come from the JSlider

    In the line 333, I am setting the unitIncrement of the scrollbar. For eg:- If the value of returncount() function is 50(which I am setting as the maximum value of the scrollbar), then the no. of increments of scrollbar should be 50-1 i.e. 49 and The value of the scrollbar, I am setting as this max value itself because I want the slider to be at the right position always.
    I want to map these time values of the slider with the values of Hashmaps(which are storing the positions, headings and statuses of the robots), in such a way that if the slider is moved towards left(initially placed at rightmost point), then the robots should go backwards in their history of positions, like reverse paths.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default Re: Problems with values that come from the JSlider

    In the line 333, I am setting the unitIncrement of the scrollbar
    In the stack trace: Line 333 looks like the constructor for JScrollBar: JScrollBar.<init> The <init> indicates a constructor.

    What are the values passed in the JScrollBar constructor when the exception is thrown?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    nishchal6 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Re: Problems with values that come from the JSlider

    ts = new JScrollBar(JScrollBar.HORIZONTAL, ClientCount.returncount(), 1, 0, ClientCount.returncount());
    ts.setUnitIncrement(ClientCount.returncount()-1);
    ts.setBlockIncrement(1);

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default Re: Problems with values that come from the JSlider

    You've posted the code but have not shown what the values are when the program executes.
    What are the numeric values that are used in the constructor? Add a println to print out the values returned by the methods called in the constructor.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    nishchal6 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Re: Problems with values that come from the JSlider

    I have checked through debugging that the value of count which is given by the function returncount() is 0.
    Basically, the idea is that there is a function known as handleStateMessage() which handles the StateMessage if it is a part of Robot Message and updates the GUI and It also sets the current state received to the DataRobot.
    I have implemented counter on this method. If this method is called say 50 times then the maximum value of scrollbar is 50 and the the no. of scrolls will be 49.
    and also based on this counter value, I am setting the keys also in the Hashmap(50 keys again if this message is called 50 times).

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default Re: Problems with values that come from the JSlider

    value of count which is given by the function returncount() is 0.
    0 is not a valid value. You make sure the value is not zero.

    This code executes without throwing an exception:
    Java Code:
          new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 1);       //<<<<<<<< OK
    Last edited by Norm; 08-13-2012 at 06:41 PM.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    nishchal6 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Re: Problems with values that come from the JSlider

    Ya, I have checked it again, the value of count is =0.
    I think the program terminates before this method handleStateMessage() is called, thats why the value is 0.
    I have declared this variable(count) globally.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default Re: Problems with values that come from the JSlider

    You'll have to check the program's logic to see why the value is 0.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    nishchal6 is offline Member
    Join Date
    Aug 2012
    Posts
    8
    Rep Power
    0

    Default Re: Problems with values that come from the JSlider

    So what exactly u think the problem is?
    U mean to say that the value of count should not be zero and if the method is called then this value will not be zero.

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,416
    Rep Power
    25

    Default Re: Problems with values that come from the JSlider

    You will need to post the code if you want anyone to look at it and see why the value is 0 when the method is called.
    The code that gives the variable a value needs to be executed BEFORE the value is used to create a JScrollBar.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default Re: Help with IllegalArgumentException: invalid range properties

    Above posts removed from Problems with values that come from the JSlider

    nishchal6, next time you have a question, start a new thread. Don't bump a two year old thread and don't hijack another poster's thread.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  14. #14
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default Re: Help with IllegalArgumentException: invalid range properties

    Quote Originally Posted by nishchal6 View Post
    Exception in thread "main" java.lang.IllegalArgumentException: invalid range properties
    at javax.swing.DefaultBoundedRangeModel.<init>(Defaul tBoundedRangeModel.java:102)
    Quite apart from anything else, you shouldn't be running Swing code on the main thread.
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 0
    Last Post: 05-27-2011, 08:46 AM
  2. Replies: 3
    Last Post: 03-24-2011, 06:18 AM
  3. JPA java.lang.IllegalArgumentException
    By johnwcv in forum Advanced Java
    Replies: 0
    Last Post: 03-17-2011, 10:17 PM
  4. Replies: 1
    Last Post: 11-20-2010, 11:28 PM
  5. proper use of IllegalArgumentException
    By vendetta in forum New To Java
    Replies: 1
    Last Post: 01-16-2010, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •