使用 JInternalFrame 和一些按钮

发布于 2024-08-31 11:15:56 字数 242 浏览 0 评论 0原文

我们可以使用 JInternalFame主框架中有一个按钮?当然,该框架包含一个JDesktopPane。该按钮应该打开JInternalFrame 如何?

Can we use a JInternalFame with a button in the main frame? The frame contains a JDesktopPane, of course. The button should open up the JInternalFrame How?

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

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

发布评论

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

评论(2

高速公鹿 2024-09-07 11:15:57

我不知道如何将 JButton 直接放在 JDesktopPane 上,但您可以使用菜单项来创建和选择 JInternalFrame。在此示例中,每个菜单项都使用 < a href="https://docs.oracle.com/javase/tutorial/uiswing/misc/action.html" rel="nofollow noreferrer">Action 中定义>JInternalFrame 选择相应的框架。

class MyFrame extends JInternalFrame {

    private Action action;

    MyFrame(JDesktopPane desktop, String name, int offset) {
        …
        action = new AbstractAction(name) {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    MyFrame.this.setSelected(true);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
            }
        };
    }

    public Action getAction() { return action; }
}

附录:正如 @camickr 所建议的,在技术上可以将 JButton 直接放在 JDesktopPane 上,但在实践中可能很难使用。

I don't know a way to put a JButton directly on a JDesktopPane, but you can use menu items to create and select a JInternalFrame. In this example, each menu item uses an Action defined in the JInternalFrame to select the corresponding frame.

class MyFrame extends JInternalFrame {

    private Action action;

    MyFrame(JDesktopPane desktop, String name, int offset) {
        …
        action = new AbstractAction(name) {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    MyFrame.this.setSelected(true);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
            }
        };
    }

    public Action getAction() { return action; }
}

Addendum: as @camickr suggests, it is technically possible to put a JButton directly on a JDesktopPane, but it might prove difficult to use in practice.

静若繁花 2024-09-07 11:15:57

我不太明白这个问题,所以我只是做一些观察。

a) JInternalFrme 就像一个框架,您可以向其中添加任何您想要的组件

b) 无论是添加到内部框架还是框架,JButton 的工作原理都是相同的

我建议您首先阅读 Swing 教程 了解工作示例。您可以从“如何使用内部框架”和“如何使用按钮”部分开始。

如果您仍然遇到问题,请发布您的 SSCCE 以显示您已尝试过的操作。

I don't really understand the question so I will just make some observations.

a) a JInternalFrme is like a frame in that you can add any component to it that you want

b) A JButton works the same whether it is added to an internal frame or a frame

I suggest you start by reading the Swing tutorial for working examples. You might start with the sections on "How to Use Internal Frames" and "How to Use Buttons".

If you still have problems then post your SSCCE that shows what you have tried.

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