943,993 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 12544
  • Java RSS
Jul 20th, 2006
0

Populate data from database into JList

Expand Post »
How to populate data from a database table into JList?
I can retrieve the data from the database table ok. No Problem but now want to populate those data into the JList. What are the code for this?
I need to know the class and methods for this.

Thanks!!!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
abc2004 is offline Offline
16 posts
since Sep 2004
Jul 20th, 2006
0

Re: Populate data from database into JList

Quote originally posted by abc2004 ...
How to populate data from a database table into JList?
I can retrieve the data from the database table ok. No Problem but now want to populate those data into the JList. What are the code for this?
I need to know the class and methods for this.

Thanks!!!!
Googling for the JList api would be a good start?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 22nd, 2006
0

Re: Populate data from database into JList

Quote originally posted by abc2004 ...
How to populate data from a database table into JList?
I can retrieve the data from the database table ok. No Problem but now want to populate those data into the JList. What are the code for this?
I need to know the class and methods for this.

Thanks!!!!
Well, as you can use a Vector to fill the JList, this would be one option.

I chose a slightly bigger solution. I wrote my own DatabaseTransaction class, which basically wraps query(), update() and get[Type]() functions of the JDBC interface.

Then I wrote my own TableModel and ListModel classes, providing a function which takes the transaction class and the column name of the value to be displayed as a parameter (resp. an array of column names and one of column captions for tables).

This works pretty smooth, as long as all of your values can be retreived as a string, which is making trouble with date/time fields.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Rotak is offline Offline
19 posts
since May 2005
Jul 23rd, 2006
0

Re: Populate data from database into JList

Wow, that sounds very nice to me. Would be nice if you could share the code. I love reuse!!! :p

THANKS!

Quote originally posted by Rotak ...
Well, as you can use a Vector to fill the JList, this would be one option.

I chose a slightly bigger solution. I wrote my own DatabaseTransaction class, which basically wraps query(), update() and get[Type]() functions of the JDBC interface.

Then I wrote my own TableModel and ListModel classes, providing a function which takes the transaction class and the column name of the value to be displayed as a parameter (resp. an array of column names and one of column captions for tables).

This works pretty smooth, as long as all of your values can be retreived as a string, which is making trouble with date/time fields.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
abc2004 is offline Offline
16 posts
since Sep 2004
Jul 23rd, 2006
0

Re: Populate data from database into JList

Quote originally posted by abc2004 ...
Wow, that sounds very nice to me. Would be nice if you could share the code. I love reuse!!! :p

THANKS!
I can imagine, that you love reuse.

The library is not ready, yet. I still need to fix problems with date/time fields (autodetecting field types from tables) and kill dependencies to other librarys used in the project.

Maybe you should simply use the Vector method for now, if you don't want to write a rather big solution like mine.

I'll check if I can post some code snippets for you, to give an idea of what the classes do. But that's not only my decission!!
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Rotak is offline Offline
19 posts
since May 2005
Jul 27th, 2006
0

Re: Populate data from database into JList

A JList with a default model could be used as a mutable list.

MutableList myList = new MutableList();
myList.getContents().removeAllElements();

myList.getContents().addElement(something);

Java Syntax (Toggle Plain Text)
  1. import javax.swing.JList;
  2. import javax.swing.DefaultListModel;
  3. public class MutableList extends JList
  4. {
  5. public MutableList()
  6. {
  7. super(new DefaultListModel());
  8. }
  9.  
  10. public DefaultListModel getContents()
  11. {
  12. return (DefaultListModel)getModel();
  13. }
  14.  
  15. }
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JTextArea question
Next Thread in Java Forum Timeline: JTable help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC