Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How to show JCheckBox component as elements of a JList ?

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example.
 
Abhinav Anand
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
Thanks a lot for such a great tip and example, it definately works.
Will keep u guys posted.
 
Our first order of business must be this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!