CheckBox in JList

hi allHow to add CheckBox item to JList?Thankz
[67 byte] By [Sana_Boya] at [2007-11-27 7:39:21]
# 1

I haven't checked if it is actually possible to do what you want, but why do you want to do that? ;-)

Having JCheckboxes inside a JList seems odd to me because both involve selection.

You could directly select items on the JList and retrieve the selection via getSelectedValues(). Or you could put JCheckboxes in a JPanel.

java_knighta at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thankz for ur attention

Actually i want to retrieve data from Database to List & user can be able to select items from that list. Then according to selected values database will be update. Yeah..

I know that i can do this using only JList, but I think its not much user friendly. If i can add checkboxes to list its better.

Sana_Boya at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 3
hello,you can check box to List also, use editor and render for that.daya
dayanandabva at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 4
> I know that i can do this using only JList, but I> think its not much user friendly. If i can add> checkboxes to list its better.This is going to clutter your code and confuse your users. Why don't you simply put your JCheckBoxes in a JPanel?
java_knighta at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 5
You should implementy custom CellRenderer and CellEditor which will return JCheckBox as rendered component and assign them in the JList.regards,Stas
StanislavLa at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 6
Google for "implements CellRenderer extends JCheckBox" and you will find plenty of examples.Regards,Stas
StanislavLa at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 7
Use a JTable, it already provides support for check boxes.
camickra at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 8

Let me start of by saying that I agree with camickr in that a JTable would both be the best and simplest solution. Why reinvent the wheel?

However, it can be done with a custom renderer if you want practice in that sort of thing. A working example can be downloaded from the website of Manning's excellent Swing book:

http://www.manning.com/robinson2/

Scroll down to the Source Code section and download the Second Edition Samples. The example you're looking for should be Chapter 10\4.

KelVarnsona at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...
# 9
I agree with camickr. You can use a JTable or a JPanel to put your checkboxes into. It depends on what your GUI is supposed to do. Without further information, the amount of advice we can give you is limited.
java_knighta at 2007-7-12 19:20:01 > top of Java-index,Desktop,Core GUI APIs...