This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how to make Jlsit as Checkbox using model in Java Swing

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have create the new JList as below:-

JList AttachFileList = new JList(model);
AttachFileList.setCellRenderer(new CheckBoxListCellRenderer());
AttachFileList.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
AttachFileList.setModel(model);



class CheckBoxListCellRenderer extends JComponent implements ListCellRenderer {
//private static final long serialVersionUID = 1L;
DefaultListCellRenderer defaultComp;
JCheckBox checkbox;

public CheckBoxListCellRenderer() {
setLayout(new BorderLayout());
defaultComp = new DefaultListCellRenderer();
/* defaultComp.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);*/
checkbox = new JCheckBox();
checkbox.setBackground(getBackground());
checkbox.setSelected(false);
// checkbox.setSelected(true);

add(checkbox, BorderLayout.WEST);
add(defaultComp, BorderLayout.CENTER);
}

public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
defaultComp.getListCellRendererComponent(list, value, index,isSelected, cellHasFocus);

checkbox.setSelected(isSelected);

return this;
}
}

problem is that when i clicked one of the item in the JList i can't deselect it my clicking it once again
please help me. . . i'll will help full to my project. . . . thanks in advance
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A renderer isn't an editor, and JList doesn't support editing. If that doesn't make much sense to you, read the API for JTable and follow the link to the tutorial on How to Use Tables, where you will find a section titled Renderers and Editors: concepts.
 
vinod Raj kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you it help full to my project
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic