How do I make a list with checkboxes in Java Swing

0 votes
Hii team,

What would be the best way to have a list of items with a checkbox each in Java Swing?
May 8, 2020 in Java by kartik
• 37,520 points
2,409 views

1 answer to this question.

0 votes

Hii @kartik,

  • Create a custom ListCellRenderer and asign it to the JList.
  • This custom ListCellRenderer must return a JCheckbox in the implementantion of getListCellRendererComponent(...) method.
  • But this JCheckbox will not be editable, is a simple paint in the screen is up to you to choose when this JCheckbox must be 'ticked' or not,

For example, show it ticked when the row is selected (parameter isSelected), but this way the check status will no be maintained if the selection changes. Its better to show it checked consulting the data below the ListModel, but then is up to you to implement the method who changes the check status of the data, and notify the change to the JList to be repainted.

Hope it help!!

answered May 8, 2020 by Niroj
• 82,840 points

Related Questions In Java

0 votes
2 answers

How do I get distinct element from list in java?

You should use a Set. it doesn't contain duplicates. If ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,188 views
0 votes
1 answer

How do I determine whether an array contains a particular value in Java?

Arrays.asList(yourArray).contains(yourValue) Warning: this doesn't work for arrays of ...READ MORE

answered Dec 21, 2020 in Java by Gitika
• 65,770 points
1,247 views
0 votes
1 answer

How do I generate random integers within a specific range in Java?

Before Java 1.7, the standard way to ...READ MORE

answered Dec 22, 2020 in Java by Gitika
• 65,770 points
807 views
0 votes
2 answers

How to make a new List in Java?

Initializing a List in Java The Java.util.List is a child ...READ MORE

answered Dec 28, 2020 in Java by Thomas Walenta
786 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
2 answers

How do I convert a String to an int in Java?

Use the lines of code mentioned below:- String ...READ MORE

answered Feb 9, 2022 in Java by Soham
• 9,710 points
3,209 views
0 votes
1 answer

how to do global variable declaration in java

Hello,​ Global varriable which is defined after the ...READ MORE

answered Apr 3, 2020 in Java by Niroj
• 82,840 points
722 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP