JXCollapsiblePane extends JXPanel { public void setCollapsed(boolean val) { boolean oldValue = isCollapsed(); this.collapsed = val; if (isAnimated() && isShowing()) { if (oldValue == isCollapsed()) { return; } if (!animateTimer.isRunning()) { collapseFiringState = oldValue; } if (oldValue) { int dimension = direction.isVertical() ? wrapper.getHeight() : wrapper.getWidth(); int preferredDimension = direction.isVertical() ? getContentPane() .getPreferredSize().height : getContentPane().getPreferredSize().width; int delta = Math.max(8, preferredDimension / 10); setAnimationParams(new AnimationParams(30, delta, 0.01f, 1.0f)); animator.reinit(dimension, preferredDimension); wrapper.getView().setVisible(true); } else { int dimension = direction.isVertical() ? wrapper.getHeight() : wrapper.getWidth(); setAnimationParams(new AnimationParams(30, Math.max(8, dimension / 10), 1.0f, 0.01f)); animator.reinit(dimension, 0); } animateTimer.start(); } else { wrapper.collapsedState = isCollapsed(); wrapper.getView().setVisible(!isCollapsed()); revalidate(); repaint(); firePropertyChange("collapsed", oldValue, isCollapsed()); } } JXCollapsiblePane();  JXCollapsiblePane(Direction direction); Container getContentPane(); void setContentPane(Container contentPanel); @Override void setLayout(LayoutManager mgr); @Override void remove(Component comp); @Override void remove(int index); @Override void removeAll(); void setAnimated(boolean animated); boolean isAnimated(); @Override void setComponentOrientation(ComponentOrientation o); void setDirection(Direction direction); Direction getDirection(); boolean isCollapsed(); void setCollapsed(boolean val); @Override Border getBorder(); @Override void setBorder(Border border); @Override void setOpaque(boolean opaque); @Override Dimension getMinimumSize(); @Override void setMinimumSize(Dimension minimumSize); @Override Dimension getPreferredSize(); @Override void setPreferredSize(Dimension preferredSize); final static String TOGGLE_ACTION; final static String COLLAPSE_ICON; final static String EXPAND_ICON; }
@Test public void testCollapsingNonShowingPane() { JXCollapsiblePane pane = new JXCollapsiblePane(); pane.add(new JLabel("some content")); PropertyChangeListener pcl = mock(PropertyChangeListener.class); pane.addPropertyChangeListener("collapsed", pcl); pane.setCollapsed(true); verify(pcl).propertyChange(argThat(is(property("collapsed", false, true)))); }