Solved

Disabled JCheckBox in JList

Posted on 2002-07-04
7
519 Views
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() {
               setBackground(UIManager.getColor("List.textBackground"));
               setForeground(UIManager.getColor("List.textForeground"));
          }

          public Component getListCellRendererComponent(JList list, Object value,
               int index, boolean isSelected, boolean hasFocus) {
               setEnabled(list.isEnabled());
               setSelected(((CheckableItem)value).isSelected());
               setFont(list.getFont());
               setText(value.toString());
               return this;
          }
     }
0
Comment
Question by:chencc77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 92

Accepted Solution

by:
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.
0
 

Author Comment

by:chencc77
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;
          }
     }
0
 
LVL 92

Expert Comment

by:objects
ID: 7130761
You should not call setSelected if the list is disabled.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

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

Expert Comment

by:objects
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.
0
 
LVL 35

Expert Comment

by:girionis
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…
Suggested Courses

617 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