I have tried to use a custom Icon for a CollapsiblePane header. It is only available for styles PLAIN and TREE, but the icon is located on the left.
And the tricky part is that I would like to have it on right side. What I get is an icon after the text, however when I have several collapsible panes, I am not able to have a correct alignement of these icons.
Any idea to solve this ?
(a custom icon on right side like DropDown style)
Here is the code I have used so far to populate a CollapsiblePanes parent :
- Code: Select all
// eventually, pad provided title with spaces to force icon location on the right ... doesn't work very well
final String title = String.format("%1$-25s", this.parentTitle);
this.collapsiblePanel = new CollapsiblePane(title);
this.collapsiblePanel.collapse(true);
this.collapsiblePanel.setEmphasized(true);
this.collapsiblePanel.setBackground(new Color(54, 71, 96));
// try to change the icon
this.collapsiblePanel.setIcon(new ImageIcon(this.getClass().getResource(
"/icons/arrow-bleu-xl.png")));
this.collapsiblePanel.setHorizontalTextPosition(SwingConstants.LEFT);
// hide Jide icon, because we can't customize it.
this.collapsiblePanel.setShowExpandButton(false);
// add a listener to update the icon
this.collapsiblePanel.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
@Override
public void paneExpanded(final CollapsiblePaneEvent arg0) {
ParentMenuItemPanel.this.collapsiblePanel.setIcon(new ImageIcon(this.getClass()
.getResource("/icons/arrow-noir-xl.png")));
ParentMenuItemPanel.this.collapsiblePanel.setBackground(new Color(67, 183, 255));
}
@Override
public void paneCollapsed(final CollapsiblePaneEvent arg0) {
ParentMenuItemPanel.this.collapsiblePanel.setIcon(new ImageIcon(this.getClass()
.getResource("/icons/arrow-bleu-xl.png")));
ParentMenuItemPanel.this.collapsiblePanel.setBackground(new Color(54, 71, 96));
}
});