Skip to main content

Checkboxes in JXtreetable

14 replies [Last post]
bobeeshek
Offline
Joined: 2009-04-25
Points: 0

Hello, i would like to create JXtreetable where each item in tree has attached checkbox. I am new to java and swing (swingx) so it is not that easy for me. I found some examples and tried it quite succesfully on jtree but i was unable to get it work on jxtreetable. I know i need to override cell rendered somehow and add custom boolean cell editor or something. I already have my custom model for that table that can store information whether item is checked or not.

Could anybody please help me or point me to the right direction? thank you very much.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
victorberthet
Offline
Joined: 2012-03-22
Points: 0

Hi, would it be possible to get the password for the demo 'xtreetable_with_checkbox.zip'. Could you please email it to me ? v i c t o r _ b e r t h e t ( a t ) h o t m a i l ( d o t ) c o m.

thanks !

britto_bics
Offline
Joined: 2008-10-23
Points: 0

vearn

I am unable to login

it asks username and password

can you just pass the source code of " jxtreetable_with_checkbox.zip "

awiting for your response.

kleopatra
Offline
Joined: 2003-06-11
Points: 0

in swingx you never ever implement a xxCellRenderer (nor subclass any defaultsomethingrenderer). Instead, implement a custom panel and a custom componentProvider which manages that panel.

BTW, why do you need a panel? The ThreeStateCheckbox should have a text property, at least that's what I would expect :-)

HTH
Jeanette

bobeeshek
Offline
Joined: 2009-04-25
Points: 0

so this way i can made my custom component (lets say panel with my desired coeckbox, label, icon etc.) which will be displayed on every node of tree? Will i be able to listen to checkbox mouseclicks this way? Could you please direct me more specifficaly, i know how overiding renderrer works but i never worked with or heard of that componentprovider, could you please direct me? thank you very much.

Basically what i am trying to accomplish is to display checkboxes in treetable with some icon (like folder or file) and text (like folder/filename) and be able to react on checkbox click. Also, this checkbox needs to be my custom component (which i already have) because i need three state checkbox.
[img]http://www.isc-net.cz/tt.png[/img]

kleopatra
Offline
Joined: 2003-06-11
Points: 0

> so this way i can made my custom component (lets say
> panel with my desired coeckbox, label, icon etc.)
> which will be displayed on every node of tree?

sure, if set it as tree cell renderer.

> Will i
> be able to listen to checkbox mouseclicks this way?

no of course not, it's a renderer. Please first understand basic swing (hint: renderer vs. editor)

> Could you please direct me more specifficaly, i know
> how overiding renderrer works but i never worked with
> or heard of that componentprovider, could you please
> direct me? thank you very much.
>

start with reading the api doc:-) The test hierarchy has some examples for custom providers, look into test classes with suffix "VisualCheck" in the renderer package.

Basically, you do something like:

[code]
class MyComponentProvider extends ComponentProvider {
// implement the abstract methods, for guidance look into the sources
}
TreeCellRenderer renderer = new DefaultTreeRenderer(new MyComponentProvider());
treeTable.setTreeCellRenderer(renderer);
[/code]

HTH
Jeanette

bobeeshek
Offline
Joined: 2009-04-25
Points: 0

Thank you, that seems to work but i am still unable to track mouseclicks on that component. i add mouselistner to mouseclick in constructor of my component but it seems to ignore these clicks. i need to know when checkbox part of component was clicked. is it even possible?

vearn
Offline
Joined: 2007-04-27
Points: 0

see my article 'when JXTreeTable meets TristateCheckBox‘-http://vearn.javaeye.com/blog/319242 (unfortunately it is written in Chinese)

search the keyword 'jxtreetable_with_checkbox.zip' in the page, then download and try the demo(it's a netbeans project)

Message was edited by: vearn

janaudy
Offline
Joined: 2004-06-22
Points: 0

vearn,

The demo requires a login, could u pls email it to me? j a n a u d y a t y a h o o d o t c o m pls?

Spinnifex
Offline
Joined: 2011-03-29
Points: 0

Hi,

Can you tell me the login too?
Or can you provide the sources on an other website?

Regards,

Spinni

bobeeshek
Offline
Joined: 2009-04-25
Points: 0

[obsolete code]

Message was edited by: bobeeshek

kschaefe
Offline
Joined: 2006-06-08
Points: 0

You need to ensure that the model believe the column is editable. A mouse listener has no effect on a renderer.

Karl

bobeeshek
Offline
Joined: 2009-04-25
Points: 0

The cell is editable but editor is textbox editing text - even if i have boolean type of column and return boolean value. It just lets me edit "true" as string for example.

rturnbull
Offline
Joined: 2005-08-27
Points: 0

If it's not the hierarchical column and tablemodel.getColumnClass for the column returns
Boolean.class, it should show a text box.
Having a boolean column and returning a boolean on its own is not enough. You also need
to tell everything it's boolean via getColumnClass in the tablemodel. Your symptoms infer
the editor thinks its a label and is using .toString

If it is the hierarchical column, I'm not sure what happens if you try and make it editable.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Is your hierarchical column a Boolean column?

Karl