-3

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Rohan Singh Dhaka
  • 173
  • 2
  • 8
  • 33
  • 2
    You don't know how to retrieve the data from the database? You don't know how to build `JList`s? Where exactly do you want us to start? What have you tried? What are stuck on? – MadProgrammer Aug 26 '12 at 20:28
  • i know how to retrieve data from JList, but don't know how to retrieve it in JList.. – Rohan Singh Dhaka Aug 26 '12 at 20:55
  • 1
    Then I'd suggest you need to visit the link that Robin has provided. It will give you head start with what you need. If you have any specific questions about anything contained within the tuts, then please feel free to ask another question – MadProgrammer Aug 26 '12 at 21:22
  • SO is not a code factory. You seem to be confused about that. – Andrew Thompson Aug 27 '12 at 01:41

1 Answers1

2

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

Robin
  • 36,233
  • 5
  • 47
  • 99
  • 4
    @RohanSinghDhaka the linked tutorial contains plenty of examples – Robin Aug 26 '12 at 20:56
  • 1
    +1 for using the model. `AbstractListModel` will be more flexible, but `DefaultListModel`, shown [here](http://stackoverflow.com/a/7620726/230513) and [here](http://stackoverflow.com/a/2937338/230513), may serve. – trashgod Aug 27 '12 at 02:50