| | |
Populate data from database into JList
![]() |
•
•
•
•
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!!!!
*Voted best profile in the world*
•
•
Join Date: May 2005
Posts: 19
Reputation:
Solved Threads: 0
•
•
•
•
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!!!!
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.
•
•
Join Date: Sep 2004
Posts: 10
Reputation:
Solved Threads: 0
Wow, that sounds very nice to me. Would be nice if you could share the code. I love reuse!!! :p
THANKS!
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.
•
•
Join Date: May 2005
Posts: 19
Reputation:
Solved Threads: 0
•
•
•
•
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!!
•
•
Join Date: Mar 2004
Posts: 763
Reputation:
Solved Threads: 38
A JList with a default model could be used as a mutable list.
MutableList myList = new MutableList();
myList.getContents().removeAllElements();
myList.getContents().addElement(something);
MutableList myList = new MutableList();
myList.getContents().removeAllElements();
myList.getContents().addElement(something);
Java Syntax (Toggle Plain Text)
import javax.swing.JList; import javax.swing.DefaultListModel; public class MutableList extends JList { public MutableList() { super(new DefaultListModel()); } public DefaultListModel getContents() { return (DefaultListModel)getModel(); } }
![]() |
Similar Threads
- retrieving a single cell of data from a MySQL database (PHP)
- How to store data in data grid to database by single mouse click in Asp.net (ASP.NET)
- please anybody to help Dropdownlist selected index problem (ASP.NET)
- copy data from excel to vb database (Visual Basic 4 / 5 / 6)
- SQL Query to populate the data from Table to Forms (MS Access and FileMaker Pro)
- Inserting Data into Access Database (Java)
- Posting form data to an Oracle database (JavaScript / DHTML / AJAX)
Other Threads in the Java Forum
- Previous Thread: JTextArea question
- Next Thread: JTable help!
| Thread Tools | Search this Thread |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans nextline openjavafx parameter php problem program project recursion recursive repositories scanner scrollbar server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows






