mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

when i use WebCheckBoxTree #702

Open wyj3531 opened 1 year ago

wyj3531 commented 1 year ago

there has some problem, how to change this icon? in WebCheckBoxTree image

mgarin commented 1 year ago

The "folder" and "leaf" icons are coming from the usual cell renderer and can be modified by providing a custom cell renderer into the tree the same way you do it with any other normal tree.

The check icon is hidden in the cell renderer that wraps provided one to add WebTristateCheckBox to it - the check icon is the WebTristateCheckBox icon. You can change it via style for checkboxtree (it contains child style for the tristate checkbox in which you can change the icon) or by providing a custom CheckBoxTreeCellRenderer via setCheckBoxTreeCellRenderer(...) method in WebCheckBoxTree, for instance a customized version of WebCheckBoxTreeCellRenderer, although I would definitely recommend modifying it via style since it's generally less painful and "dirty" approach.

wyj3531 commented 1 year ago

when i use WebTristateCheckBox checkBox =tree.getCheckBoxCellRenderer().getCheckBox(); and set icon ,state change icon don not change ,why ?

WebTristateCheckBox checkBox =tree.getCheckBoxCellRenderer().getCheckBox(); checkBox.setIcon(icon); checkBox.setSelectedIcon(selectIcon); checkBox.setPressedIcon(selectIcon);

wyj3531 commented 1 year ago

and also i set the code ,it also no correct tree.getUI().setExpandedIcon(DemoIcons.twitter16); tree.getUI().setCollapsedIcon(DemoIcons.facebook16); image

mgarin commented 1 year ago

when i use WebTristateCheckBox checkBox =tree.getCheckBoxCellRenderer().getCheckBox(); and set icon ,state change icon don not change ,why ?

WebTristateCheckBox checkBox =tree.getCheckBoxCellRenderer().getCheckBox(); checkBox.setIcon(icon); checkBox.setSelectedIcon(selectIcon); checkBox.setPressedIcon(selectIcon);

WebLaF tristate checkbox doesn't use those icons to paint its states - instead it uses a custom icon installed by the AbstractStateButtonPainter to paint states based on the tristatecheckbox style: https://github.com/mgarin/weblaf/blob/master/modules/ui/src/com/alee/skin/light/resources/tristatecheckbox.xml#L25

Unfortunately I don't have a good/quick solution for this except for suggesting to use custom style for the tree/tristatecheckbox instead of custom icons. Checkboxes were implemented in this way in advance to avoid limitations of multiple icons usage for when state animations will be implemented for the component styles.


and also i set the code ,it also no correct tree.getUI().setExpandedIcon(DemoIcons.twitter16); tree.getUI().setCollapsedIcon(DemoIcons.facebook16);

This is a good catch, it is indeed a bug - the +/- icons are basically hardcoded in WebTreeUI to return specific predefined icons. I've added a separate issue to fix this in future updates: #703