Tuesday, April 25, 2017

JSplitPane: Programmatically hide/show

http://stackoverflow.com/questions/4934499/how-to-set-jsplitpane-divider-collapse-expand-state/5127898#5127898
http://stackoverflow.com/questions/9177182/how-can-you-programmatically-set-the-jsplitpane-to-hide-the-right-bottom-compone


Sample Code
jSplitPane3.getRightComponent().setMinimumSize(new Dimension());
        jSplitPane3.addAncestorListener(new AncestorListener() {
            @Override
            public void ancestorAdded(AncestorEvent event) {
                try {

                    jSplitPane3.setDividerLocation(1.0); // Divider is positioned
                    Field m = BasicSplitPaneUI.class.getDeclaredField("keepHidden");
                    m.setAccessible(true);
                    m.set(jSplitPane3.getUI(), true); //sp.removeAncestorListener(this); // Uncomment for a one-shot event
                    jSplitPane3.removeAncestorListener(this); // Uncomment for a one-shot event
                } catch (NoSuchFieldException ex) {
                    logger.error("", ex);
                } catch (SecurityException ex) {
                    logger.error("", ex);
                } catch (IllegalArgumentException ex) {
                    logger.error("", ex);
                } catch (IllegalAccessException ex) {
                    logger.error("", ex);
                }
            }

            @Override
            public void ancestorRemoved(AncestorEvent event) {
            }

            @Override
            public void ancestorMoved(AncestorEvent event) {
            }
        });



Another

if (jSplitPane3.getDividerLocation() > jSplitPane3.getMaximumDividerLocation()) {
}


No comments:

Post a Comment