开发者

Accordion Menu to show set of images in java

I'm doing a Java project which includes little bit of graphical stuffs. I want to display set of BufferedImages under Accordion menu kind of thing. that means when I click on one Accordion menu root item it should display set of images under that name and when clicking on another root menu item it should show another set of images. How could开发者_运维百科 I implement this with Java?. Is there any way to add JPanel as Accordion menu leaf item? If anyone can provide sample code it is really appreciable.


Couldn't resist some fun: turns out that it's possible to tweak a JXTaskPaneContainer (in SwingX) a bit to behave similar to an accordion. All that's needed it to force at most one of the contained JXTaskPaneContainers to be expanded. Something like the code snippet:

    JXTaskPaneContainer container = new JXTaskPaneContainer() {

        private JXTaskPane current;

        private PropertyChangeListener expansionListener;

        /**
         * @inherited <p>
         */
        @Override
        protected void addImpl(Component comp, Object constraints, int index) {
            super.addImpl(comp, constraints, index);
            if (comp instanceof JXTaskPane) {
                grabExpansionControl((JXTaskPane) comp);
            }
        }

        private void grabExpansionControl(JXTaskPane comp) {
            if (current != null) {
                comp.setCollapsed(true);
            } else {
                current = comp;
                comp.setCollapsed(false);
            }
            comp.addPropertyChangeListener("collapsed",
                    getExpansionListener());
        }

        private void updateCurrentTaskPane(JXTaskPane source) {
            if (source != current) {
                if (!source.isCollapsed()) {
                    if (current != null) {
                        current.setCollapsed(true);
                    }
                    current = source;
                }
            }
        }

        private PropertyChangeListener createExpansionListener() {
            PropertyChangeListener l = new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    // TODO Auto-generated method stub
                    updateCurrentTaskPane((JXTaskPane) evt.getSource());
                }
            };
            return l;
        }


        private PropertyChangeListener getExpansionListener() {
            if (expansionListener == null) {
                expansionListener = createExpansionListener();
            }
            return expansionListener;
        }


    };
    ((VerticalLayout) container.getLayout()).setGap(0);


Well a little bit of googling and I found this link . It may be helpful for you - http://code.google.com/p/martin-personal-project/downloads/detail?name=SwingAccordionMenu.zip&can=2&q=

You will get a ZIP file , unzip and run the SwingAccordionMenu.jar, you will get accordion as output like -

Accordion Menu to show set of images in java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜