Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    25
    Rep Power
    0

    Default JSpinner and objects

    Hey,

    Is there some way I can fill a JSpinner with objects instead of string[]:

    Now I'm using this:

    Java Code:
      String[] statusLijst = new String[rep.getStatusen().size()];
          for(int i=0; i < rep.getStatusen().size();i++)
          {
              Status s = (Status)rep.getStatusen().toArray()[i];
              statusLijst[i] = s.getNaam();
          }
          
          model = new SpinnerListModel(statusLijst);
          spinnerStatus = new JSpinner(model);
          spinnerStatus.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    But It would be a better if I could place objects inside the model in stead of a string[]

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: JSpinner and objects

    Can't you just use an array of whatever Object you want? The API is your friend: SpinnerListModel (Java Platform SE 7 )
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    25
    Rep Power
    0

    Default Re: JSpinner and objects

    Quote Originally Posted by KevinWorkman View Post
    Can't you just use an array of whatever Object you want? The API is your friend: SpinnerListModel (Java Platform SE 7 )
    If I do something like this, I get: Status@12345 instead of the stringvalue from status.getName();

    Java Code:
       Status[] statusLijst = new Status[rep.getStatusen().size()];
          for(int i=0; i < rep.getStatusen().size();i++)
          {
              statusLijst[i] = (Status)rep.getStatusen().toArray()[i];
             
          }
          
          model = new SpinnerListModel(statusLijst);
          spinnerStatus = new JSpinner(model);
          spinnerStatus.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    Can you explain what I am doing wrong? thx

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: JSpinner and objects

    Java doesn't know how to represent any arbitrary Object (such as your Status Object) as a String, so you get that gobbledygook (which is specified in the API for the Object class). You can override the toString() method and return a String representation of your Status Object, or you can create a function that takes a Status Object and returns a String for printing or displaying.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Get datetime from Jspinner
    By Bibhukalyana in forum New To Java
    Replies: 2
    Last Post: 05-30-2013, 06:19 AM
  2. Help with JSpinner
    By cyentw in forum New To Java
    Replies: 4
    Last Post: 02-11-2013, 05:40 AM
  3. Help me! how to use JSpinner
    By ngankt2 in forum AWT / Swing
    Replies: 1
    Last Post: 11-05-2010, 07:07 PM
  4. JSpinner resizes, I don't want that.
    By JosAH in forum AWT / Swing
    Replies: 4
    Last Post: 05-30-2010, 09:11 AM
  5. Jtable Jspinner help
    By chiragkini in forum AWT / Swing
    Replies: 5
    Last Post: 08-15-2009, 04:36 AM

Posting Permissions

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