数据从数据库到JList [英] Data from database to JList
问题描述
我创建了一个数据库,其中的表名称之一是Location(位置),其中有2列分别名为Stadium(体育场)和City(城市).我希望每列中的数据都应该在2 JList中检索,但是我不知道如何.你们能告诉我怎么做吗?
从数据库显示表的通常方法当然是JTable
.但是,如果您想选择2个JList
,则基本上是相同的原理.
基于数据库的内容创建模型(在本例中为ListModel
).您可能只是从AbstractListModel
扩展而来.一旦有了模型,只需在构造函数中传递模型即可为它创建JList
.
请参见 如何使用列表 教程,并特别注意该教程的创建模型部分
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?
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
这篇关于数据从数据库到JList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!