i try to use JXCollapsiblePane (SwingX version 1.6.5.1) in a Java 7 Swing application. When writing a small test app i see the following problems:
- the toggle button is not in sync with the collapsible pane, i.e. i first have to click the button and only then it's in sync with the pane's state
- i only see one icon (collapsed or expanded) which always stays the same, regardless in which toggle state we are
I use the following code which is SSCCE:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.UIManager;
import org.jdesktop.swingx.JXCollapsiblePane;
import org.jdesktop.swingx.JXFrame;
public class JXCollapsiblePaneBsp {
public static void main(String[] args) {
JXFrame frame = new JXFrame("JXCollapsiblePane-Example", true);
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
frame.add(new TestContainer());
JXCollapsiblePane cp = new JXCollapsiblePane();
cp.setAnimated(true);
JLabel label = new JLabel("Text");
label.setForeground(Color.WHITE);
JButton butt = new JButton("click");
JPanel panel = new JPanel(new FlowLayout());
panel.setOpaque(true);
panel.setBackground(Color.DARK_GRAY);
panel.add(label);
panel.add(butt);
cp.add(panel);
JPanel northContainer = new JPanel();
northContainer.setLayout(new BorderLayout());
JLabel title = new JLabel("Test");
northContainer.add(title, BorderLayout.WEST);
Action toggleAction = cp.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION);
toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON, UIManager.getIcon("Tree.expandedIcon"));
toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON, UIManager.getIcon("Tree.collapsedIcon"));
JToggleButton toggleButt = new JToggleButton(toggleAction);
toggleButt.setText("");
northContainer.add(toggleButt, BorderLayout.EAST);
container.add(cp, BorderLayout.CENTER);
container.add(northContainer, BorderLayout.NORTH);
frame.setStartPosition(JXFrame.StartPosition.CenterInScreen);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
Is this a compatibility problem or what am i doing wrong here ? Thank you!
UPDATE: After debugging the code for some hours now i can say that the problem seems to be not finishing animations. The timer always cancels events and therefore a started animation (up or down) can never come to an end. When setting
cp.setAnimated(false);
the expand/collapse actions work fine (of course without animation).