File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Customizing a JList with data variables.

 
Marvin Legend
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello my friends

I have a question, I would like that when I created a JList, I could put in it, the value of a text followed by the value of any variable, eg:

String name = "Anna";
int result = 17;

A print of the list would look like:



I would like to set the list what types of information will get into it, because these data will be captured variables.
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put these two values to the list model by addElement(name +" " + result);
Or if you have a object of a model class, addElement(model.getName() +" " + model.getResult());
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Pramuditha Rathnayake wrote:You can put these two values to the list model by addElement(name +" " + result);
Or if you have a object of a model class, addElement(model.getName() +" " + model.getResult());

That's fine but just to ensure that the values never null.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic