The DecoratedListUI
and DecoratedTreeUI
render clickable/animatable icons on rows in lists/trees.
The demo in this showcase app offers a few ideas for potential decorations.
Each decoration is basically an actionable icon that implements this interface:
public interface ListDecoration { Icon getIcon(JList list, Object value, int row, boolean isSelected, boolean cellHasFocus, boolean isRollover, boolean isPressed); boolean isVisible(JList list, Object value, int row, boolean isSelected, boolean cellHasFocus); ActionListener getActionListener(JList list, Object value, int row, boolean isSelected, boolean cellHasFocus); Point getLocation(JList list, Object value, int row, boolean isSelected, boolean cellHasFocus); }
And then to integrate it:
JList list = new JList(); list.putClientProperty( DecoratedListUI.KEY_DECORATIONS, new ListDecoration[] { decoration1, decoration2, etc. }); list.setUI(new DecoratedListUI());
The decorations are "stamped" on each row, like the CellRendererPane
. That is: they don't exist in the component hierarchy, and the ComponentUI
is responsible for interpreting mouse clicks and triggering the appropriate ActionListener
.
This is great way to add extra functionality for power users without adding too much visual clutter.
However: you need to decide what you want to do about accessibility. This class represents a UI choice that is not accessible. This may be OK if every feature that is part of a decoration is also available somewhere else in your application. For example: if you also have a menu shortcut that activates the same feature.
The alternative is to try to layer actual JComponents
into your UI, and that has its own complex set of challenges for a list or a tree.