问题
I created a database, in which one of the table name is Location which has 2 columns named Stadium and City. I want that data in each column should get retrieved in 2 JList, but I don't know how. Can you guys tell me how to do it?
回答1:
The normal way to display a table from a database is of course a JTable
. But if you want to opt for 2 JList
s instead, it is basically the same principle.
Create a model based on the contents of the database (in this case a ListModel
). You can probably just extend from AbstractListModel
. Once you have your model, it is trivial to create a JList
for it by just passing the model in the constructor.
See the How to use lists tutorial and pay special attention on the Creating a model part of that tutorial
来源:https://stackoverflow.com/questions/12133621/data-from-database-to-jlist