在java中显示图像集的手风琴菜单

发布于 2024-11-07 05:19:37 字数 192 浏览 0 评论 0原文

我正在做一个 Java 项目,其中包含一些图形内容。我想在手风琴菜单之类的东西下显示一组 BufferedImages。这意味着当我单击一个手风琴菜单根项时,它应该显示该名称下的一组图像,当单击另一个根菜单项时,它应该显示另一组图像。我怎样才能用Java实现这个?有没有办法将 JPanel 添加为 Accordion 菜单叶项?如果有人能提供示例代码,那就非常感激了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坐在坟头思考人生 2024-11-14 05:19:37

无法抗拒一些乐趣:事实证明,可以对 JXTaskPaneContainer(在 SwingX 中)进行一些调整,使其表现得类似于手风琴。所需要的只是强制最多扩展其中一个包含的 JXTaskPaneContainer。就像代码片段一样:

    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);

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);
尐偏执 2024-11-14 05:19:37

嗯,稍微谷歌搜索一下,我发现了这个链接。
这可能对你有帮助 -
http:// /code.google.com/p/martin-personal-project/downloads/detail?name=SwingAccordionMenu.zip&can=2&q=

您将获得一个 ZIP 文件,解压并运行 SwingAccordionMenu.jar,你会得到手风琴作为输出,例如 -
在此处输入图像描述

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 -
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文