开发者

multiple column display in JList

Is it po开发者_Python百科ssible to have multiple column display in JList ????


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.


Use a JTable which is designed for this purpose.


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:

multiple column display in JList

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

multiple column display in JList

(Both from my current project.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜