Populate data from database into JList

Reply

Join Date: Sep 2004
Posts: 10
Reputation: abc2004 is an unknown quantity at this point 
Solved Threads: 0
abc2004 abc2004 is offline Offline
Newbie Poster

Populate data from database into JList

 
0
  #1
Jul 20th, 2006
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!!!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Populate data from database into JList

 
0
  #2
Jul 20th, 2006
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?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 19
Reputation: Rotak is an unknown quantity at this point 
Solved Threads: 0
Rotak Rotak is offline Offline
Newbie Poster

Re: Populate data from database into JList

 
0
  #3
Jul 22nd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 10
Reputation: abc2004 is an unknown quantity at this point 
Solved Threads: 0
abc2004 abc2004 is offline Offline
Newbie Poster

Re: Populate data from database into JList

 
0
  #4
Jul 23rd, 2006
Wow, that sounds very nice to me. Would be nice if you could share the code. I love reuse!!! :p

THANKS!

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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 19
Reputation: Rotak is an unknown quantity at this point 
Solved Threads: 0
Rotak Rotak is offline Offline
Newbie Poster

Re: Populate data from database into JList

 
0
  #5
Jul 23rd, 2006
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!!
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Populate data from database into JList

 
0
  #6
Jul 27th, 2006
A JList with a default model could be used as a mutable list.

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

myList.getContents().addElement(something);

  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. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC