我尝试在Java 7 Swing应用程序中使用JXCollapsiblePane(SwingX版本1.6.5.1)。在编写一个小型测试应用程序时,我会看到以下问题:
我使用以下代码,即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);
}
}
这是兼容性问题还是我在这里做错了什么? 谢谢!
更新:调试代码几个小时后,我可以说问题似乎没有完成动画。计时器总是取消事件,因此启动的动画(向上或向下)永远不会结束。 设置时
cp.setAnimated(false);
展开/折叠操作正常(当然没有动画)。