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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

735 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