File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to show JCheckBox component as elements of a JList ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to show JCheckBox component as elements of a JList ?" Watch "How to show JCheckBox component as elements of a JList ?" New topic
Author

How to show JCheckBox component as elements of a JList ?

Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi guys,
I want to show a dialog with JList component in it. Now i want to display a JCheckBox component instead of a simple text label in the JList. So that it would enable my user to select/unselect the checkbox when the users click on an item in the JList.
I have found that there is no method to provide an editor for the the JList component. It is possible to provide an editor in the JTable and JTree.
Any suggetions are welcome.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

I would recomend not using a JList for what you want to do. It just doesn't make sense really.
I asume that the reason you need JCheckBox's in a JList is so that you can have a large list and scroll through the list of JCheckbox elements. If you have another reason, I would like to know what it is.
However, if my assumption is correct you can put a JPanel in a JScrollPane. Place all your JCheckBoxes on the JPanel. Then you can scroll up and down the JPanel if you have that many JCheckBox elements.


GenRocket - Experts at Building Test Data
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Vishal,
Here's a suggestion: Use a "JTable" with one column. Hide the "grid" lines (using method "setShowHorizontalLines()" in class "JTable"). Make the class of the column "Boolean" (see method "getColumnClass()" in interface "TableModel"). The default renderer for such a column is a "JCheckBox". Finally, place the "JTable" in a "JScrollPane". This should give you the desired effect.
Hope this has helped you.
Good Luck,
Avi.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Example.
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi guys,
Thanks a lot for such a great tip and example, it definately works.
Will keep u guys posted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to show JCheckBox component as elements of a JList ?