Data from database to JList

本小妞迷上赌 提交于 2019-12-14 03:36:27

问题


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 JLists 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!