Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a per-tree wide selection setting #245

Closed

Conversation

ingokegel
Copy link
Contributor

Even when using wide selection by default, there are use cases where no selection background is desired, for example if the renderer shows the selected node in bold text without any selection background.

DevCharly added a commit that referenced this pull request Jan 21, 2021
- paint non-wide selection in FlatTreeUI.paintRow() instead of using reflection to change private field in DefaultTreeCellRenderer
- use DefaultTreeCellRenderer.getBackgroundSelectionColor() as selection color (if possible)
- added boolean client property JTree.paintSelection to disable selection painting in FlatTreeUI.paintRow()
- FlatComponents2Test:
  - added checkboxes for wideSelection and paintSelection client properties
  - added possibility to test various kinds of tree cell renderers
  - added JXTree, JIDE CheckBoxTree

(PR #245)
@DevCharly
Copy link
Collaborator

Thanks, Ingo.

Good idea.
But using reflection to modify a private JRE field is a problem
because this breaks functionality if access is denied by JRE,
which will be the default in Java 16 iI think
(see https://openjdk.java.net/jeps/396).

To avoid the use of reflection, I've implemented non-wide selection painting into FlatTreeUI.paintRow()
in the same way as done in DefaultTreeCellRenderer.paint() if DefaultTreeCellRenderer.fillBackground is true.
A renderer can paint over the selection background if necessary.

Have also added an additional client property to disable selection painting in FlatTreeUI.paintRow().
Then the renderer is responsible for selection painting.

Please try this branch:
https://github.com/JFormDesigner/FlatLaf/tree/tree_wide_selection

@ingokegel
Copy link
Contributor Author

Thank you, this is an excellent solution and it's now very flexible!

@ingokegel ingokegel closed this Jan 21, 2021
DevCharly added a commit that referenced this pull request Jan 21, 2021
Added a per-tree wide selection setting
DevCharly added a commit that referenced this pull request Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants