This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JCheckBox in JXTreeTable  RSS feed

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have written a simplistic program where I wanted to show a JCheckBox in an JXTreeTable, but it does not work. Can you give me an hint what I could try?

Thank you

 
Bartender
Posts: 1104
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the column 'class' is boolean, the JTable will show the column as a checkbox. Same applies for JXTreeTable. You need to override the getColumnClass of the TreeTableModel to return the Boolean.class for the column that you want to show as checkbox.
 
M Bryan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my current try but the field just stays empty, no matter if i use line 57 or not:



 
Sheriff
Posts: 21450
95
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using the first boolean value to set the checked state, but that indicates the selected state of the cell - in other words, whether or not it's selected in the tree. That's different from whether or not the check box should be checked. That's where the value comes in. Try replacing line 69 with this:
Although I must admit I am surprised that JXTreeTable doesn't have support for Boolean.class out-of-the-box like JTable has. With JTable, all you need to do is let your TableModel specify the column class is Boolean.class (like you're doing) and it will display a check box automatically (unless you override this behaviour).
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote: Although I must admit I am surprised that JXTreeTable doesn't have support for Boolean.class out-of-the-box like JTable has. With JTable, all you need to do is let your TableModel specify the column class is Boolean.class (like you're doing) and it will display a check box automatically (unless you override this behaviour).



No, it does. It works fine for me and I am not using a TableCellRenderer. But, I have the second column as a boolean and the first column is a String.
I am beginning to think if Bryan has the first column itself as a boolean.
 
M Bryan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:You're using the first boolean value to set the checked state, but that indicates the selected state of the cell - in other words, whether or not it's selected in the tree. That's different from whether or not the check box should be checked. That's where the value comes in. Try replacing line 69 with this:
Although I must admit I am surprised that JXTreeTable doesn't have support for Boolean.class out-of-the-box like JTable has. With JTable, all you need to do is let your TableModel specify the column class is Boolean.class (like you're doing) and it will display a check box automatically (unless you override this behaviour).



Unfortunately that didn't do it. If JXTreeTable has an own implementation of what I need I'm sure that one's better than mine. How do I use it?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

M Bryan wrote: If JXTreeTable has an own implementation of what I need I'm sure that one's better than mine. How do I use it?


There is no special implementation. It is same as the JTable where you get a checkbox by overriding the getColumnClass which you have already done. Remove the TableCellRenderer altogether and make sure you are returning a boolean value in the getValueAt method for that column.

Note: However, this does not work for the first column and works from second column onwards.
 
M Bryan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I figured it out how to get the treetable to show checkboxes in a column. It now has checkboxes in every line, but I think I can solve that problem.
But there is still a problem: If I click on a checkbox, its visible state does not change. I only can see a change if I move the cursor away from that specific checkbox. Why?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with just overriding getColumnClass and without using a renderer and it is working fine for me. You need to implement the getValueAt and setValueAt correctly. However, if you are still using a renderer, then I am not sure...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!