开发者

JList with custom cell renderer vs Jtable

开发者 https://www.devze.com 2023-01-20 20:36 出处:网络
My current application uses a JList and everything is well (the only customization I did was to set the italic font on some of the rows).

My current application uses a JList and everything is well (the only customization I did was to set the italic font on some of the rows).

Now I want to "upgrade开发者_如何学C" the user interface and instead of just labels in the List, I want a checkbox and a text field to be able to update the entry.

I started changing the code and adding a custom cell renderer and a custom cell model. My current problem is that the JPanel that the cell renderer is returning is not using the whole width of the container, so several list items are actually shown on the same line.

But now, I am wondering whether I should just change the whole thing to use JTable. I still need to add / remove items in the list though...

Any suggestion which one is better ? and if going with the JList, how should I go about fixing my current problem ?


In my experience using JTable is usually easier as it allows more complex data and functionality out-of-the-box. Usually when I try to do something the JList can't do, I just switch to JTable without a second thought. What you want sounds like something that should be pretty trivial to implement in a table. I suggest you try it out with some mock data to see if you can make it look and work the way you like (especially in case you want it to look like a list).


Try calling setLayoutOrientation(JList.VERTICAL) on your JList. That will restrict JList to a single column.

0

精彩评论

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

关注公众号