File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JCheckBox in JXTreeTable

 
M Bryan
Ranch Hand
Posts: 64
  • 0
  • 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

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • 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
  • 0
  • 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:



 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • 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
  • 0
  • 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: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • 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
  • 0
  • 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: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • 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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic