Swing JList: how to show String from an object? [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • How do I print my Java object without getting “SomeType@2f92e0f4”?

    10 answers



  • How to override toString() properly in Java?

    8 answers




this confuses me.
i add objects in JList , like below:



public class RequestListModel extends AbstractListModel<Request> {

private static final long serialVersionUID = 1L;
private List<Request> data = null;

public RequestListModel (List<Request> data) {
this.data = data;
}

@Override
public int getSize() {
return this.data.size();
}

@Override
public Request getElementAt(int index) {
Request request = data.get(index);
return request;
}}

private JList<Request> getList() {
ListModel<Request> model = new RequestListModel(this.requestList);
if(jlist_from == null) {
jlist_from = new JList<Request>(model);
} else {
jlist_from.setModel(model);
}
return jlist_from;
}


but when i run the program, it just shows the object's address :
enter image description here



so how would i show the text from the object ?
thank you very much.










share|improve this question















marked as duplicate by Elliott Frisch java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 3:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    -1
    down vote

    favorite













    This question already has an answer here:




    • How do I print my Java object without getting “SomeType@2f92e0f4”?

      10 answers



    • How to override toString() properly in Java?

      8 answers




    this confuses me.
    i add objects in JList , like below:



    public class RequestListModel extends AbstractListModel<Request> {

    private static final long serialVersionUID = 1L;
    private List<Request> data = null;

    public RequestListModel (List<Request> data) {
    this.data = data;
    }

    @Override
    public int getSize() {
    return this.data.size();
    }

    @Override
    public Request getElementAt(int index) {
    Request request = data.get(index);
    return request;
    }}

    private JList<Request> getList() {
    ListModel<Request> model = new RequestListModel(this.requestList);
    if(jlist_from == null) {
    jlist_from = new JList<Request>(model);
    } else {
    jlist_from.setModel(model);
    }
    return jlist_from;
    }


    but when i run the program, it just shows the object's address :
    enter image description here



    so how would i show the text from the object ?
    thank you very much.










    share|improve this question















    marked as duplicate by Elliott Frisch java
    Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 12 at 3:43


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite












      This question already has an answer here:




      • How do I print my Java object without getting “SomeType@2f92e0f4”?

        10 answers



      • How to override toString() properly in Java?

        8 answers




      this confuses me.
      i add objects in JList , like below:



      public class RequestListModel extends AbstractListModel<Request> {

      private static final long serialVersionUID = 1L;
      private List<Request> data = null;

      public RequestListModel (List<Request> data) {
      this.data = data;
      }

      @Override
      public int getSize() {
      return this.data.size();
      }

      @Override
      public Request getElementAt(int index) {
      Request request = data.get(index);
      return request;
      }}

      private JList<Request> getList() {
      ListModel<Request> model = new RequestListModel(this.requestList);
      if(jlist_from == null) {
      jlist_from = new JList<Request>(model);
      } else {
      jlist_from.setModel(model);
      }
      return jlist_from;
      }


      but when i run the program, it just shows the object's address :
      enter image description here



      so how would i show the text from the object ?
      thank you very much.










      share|improve this question
















      This question already has an answer here:




      • How do I print my Java object without getting “SomeType@2f92e0f4”?

        10 answers



      • How to override toString() properly in Java?

        8 answers




      this confuses me.
      i add objects in JList , like below:



      public class RequestListModel extends AbstractListModel<Request> {

      private static final long serialVersionUID = 1L;
      private List<Request> data = null;

      public RequestListModel (List<Request> data) {
      this.data = data;
      }

      @Override
      public int getSize() {
      return this.data.size();
      }

      @Override
      public Request getElementAt(int index) {
      Request request = data.get(index);
      return request;
      }}

      private JList<Request> getList() {
      ListModel<Request> model = new RequestListModel(this.requestList);
      if(jlist_from == null) {
      jlist_from = new JList<Request>(model);
      } else {
      jlist_from.setModel(model);
      }
      return jlist_from;
      }


      but when i run the program, it just shows the object's address :
      enter image description here



      so how would i show the text from the object ?
      thank you very much.





      This question already has an answer here:




      • How do I print my Java object without getting “SomeType@2f92e0f4”?

        10 answers



      • How to override toString() properly in Java?

        8 answers








      java swing jlist






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 7:35









      4dc0

      42539




      42539










      asked Nov 12 at 3:41









      Brave ru

      214




      214




      marked as duplicate by Elliott Frisch java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 12 at 3:43


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Elliott Frisch java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 12 at 3:43


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted











          it just show the object's address




          The default renderer for a JList simply invokes the toString() method of the object, which by default is the objects address.



          You should provide a custom renderer for your JList. The render allows you to access the object and display any data from the object in any format that you wish. Read the section from the Swing tutorial on Using a Custom Renderer.



          A simpler solution is to implement a custom toString() method in your object. Although this approach is not recommended since the toString() should be used to describe the object when debugging.



          Also, there is no reason to create a custom ListModel. You can just use the DefaultListModel to hold your Request objects.






          share|improve this answer























          • much thanks for your kindly help , camickr
            – Brave ru
            Nov 12 at 6:57


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted











          it just show the object's address




          The default renderer for a JList simply invokes the toString() method of the object, which by default is the objects address.



          You should provide a custom renderer for your JList. The render allows you to access the object and display any data from the object in any format that you wish. Read the section from the Swing tutorial on Using a Custom Renderer.



          A simpler solution is to implement a custom toString() method in your object. Although this approach is not recommended since the toString() should be used to describe the object when debugging.



          Also, there is no reason to create a custom ListModel. You can just use the DefaultListModel to hold your Request objects.






          share|improve this answer























          • much thanks for your kindly help , camickr
            – Brave ru
            Nov 12 at 6:57















          up vote
          0
          down vote



          accepted











          it just show the object's address




          The default renderer for a JList simply invokes the toString() method of the object, which by default is the objects address.



          You should provide a custom renderer for your JList. The render allows you to access the object and display any data from the object in any format that you wish. Read the section from the Swing tutorial on Using a Custom Renderer.



          A simpler solution is to implement a custom toString() method in your object. Although this approach is not recommended since the toString() should be used to describe the object when debugging.



          Also, there is no reason to create a custom ListModel. You can just use the DefaultListModel to hold your Request objects.






          share|improve this answer























          • much thanks for your kindly help , camickr
            – Brave ru
            Nov 12 at 6:57













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted







          it just show the object's address




          The default renderer for a JList simply invokes the toString() method of the object, which by default is the objects address.



          You should provide a custom renderer for your JList. The render allows you to access the object and display any data from the object in any format that you wish. Read the section from the Swing tutorial on Using a Custom Renderer.



          A simpler solution is to implement a custom toString() method in your object. Although this approach is not recommended since the toString() should be used to describe the object when debugging.



          Also, there is no reason to create a custom ListModel. You can just use the DefaultListModel to hold your Request objects.






          share|improve this answer















          it just show the object's address




          The default renderer for a JList simply invokes the toString() method of the object, which by default is the objects address.



          You should provide a custom renderer for your JList. The render allows you to access the object and display any data from the object in any format that you wish. Read the section from the Swing tutorial on Using a Custom Renderer.



          A simpler solution is to implement a custom toString() method in your object. Although this approach is not recommended since the toString() should be used to describe the object when debugging.



          Also, there is no reason to create a custom ListModel. You can just use the DefaultListModel to hold your Request objects.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 3:59

























          answered Nov 12 at 3:43









          camickr

          273k15126239




          273k15126239












          • much thanks for your kindly help , camickr
            – Brave ru
            Nov 12 at 6:57


















          • much thanks for your kindly help , camickr
            – Brave ru
            Nov 12 at 6:57
















          much thanks for your kindly help , camickr
          – Brave ru
          Nov 12 at 6:57




          much thanks for your kindly help , camickr
          – Brave ru
          Nov 12 at 6:57



          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?