Disabled JCheckBox in JList

Posted on 2002-07-04
Last Modified: 2012-06-27
Hi, I am using a JList that contain JCheckBox, i use the follow ListRender to add the checkbox into JList. In my code, sometimes i need to disabled the JList, but the problem is the JList has been disabled but the JCheckBox still can be checked.

//list renderer
class CheckListRenderer extends JCheckBox implements ListCellRenderer {
          public CheckListRenderer() {

          public Component getListCellRendererComponent(JList list, Object value,
               int index, boolean isSelected, boolean hasFocus) {
               return this;
Question by:chencc77
  • 3
  • 2
LVL 92

Accepted Solution

objects earned 30 total points
ID: 7129466
Your renderer just handles painting the list.
You must have some code elsewhere that toggles the CheckableItem value, it is that code that you need to disable.

Author Comment

ID: 7129490
Hi objects, this is the CheckableItem class, what should i edit. thanks.

class CheckableItem {
          private String  str;
          private boolean isSelected;
          public CheckableItem(String str) {
               this.str = str;
               isSelected = false;
          public void setSelected(boolean b) {
               isSelected = b;
          public boolean isSelected() {
               return isSelected;
          public String toString() {
               return str;
LVL 92

Expert Comment

ID: 7130761
You should not call setSelected if the list is disabled.
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Author Comment

ID: 7130854
hi, i am not clear with ur comment that how to not call setSelected.
LVL 92

Expert Comment

ID: 7130926
Somewhere in your code you must call setSelected as a result of a checkbox being selected in the list.
If the list is disabled then you should not be doing this.
LVL 35

Expert Comment

ID: 8893996
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to objects

Please leave any comments here within the
next seven days.


Cleanup Volunteer

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven project error 5 53
couple of eclipse 5 35
java jdbc batch example 8 29
hibernate example issues from command prompt 10 39
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now