Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple column display in JList

Tags:

java

swing

jlist

Is it possible to have multiple column display in JList ????

like image 242
Mahesh Gupta Avatar asked Mar 13 '11 05:03

Mahesh Gupta


2 Answers

Absolutely! You need to make a call to setLayoutOrientation which indicates to the list how it should wrap its data before going to a new row. You can use JList.HORIZONTAL_WRAP or JList.VERITCAL_WRAP. This tells the data to be displayed as usual (as a list) and then wrap when it reaches the bottom.

If you want to combine that call with setVisibleRowCount(-1), you can then display as many items possible in the space that is available.

like image 192
JasCav Avatar answered Sep 28 '22 04:09

JasCav


To compare the two answers by camickr and JasCav:

  • If you need multiple columns of data which somehow is linked together (like first column user name, second column icons of these users), a JTable is the right thing to use.
  • If you simply want to use the screen space better by filling multiple columns of the same data, use the wrapping JList like described by JasCav.

Here is a wrapped JList of Icon objects:

wrapped JList

Here is a JTable with icons in the second row and a special TableCellRenderer:

jTable

(Both from my current project.)

like image 38
Paŭlo Ebermann Avatar answered Sep 28 '22 03:09

Paŭlo Ebermann