使用JInternalFrame和一些按钮 [英] Using JInternalFrame and some button

查看:106
本文介绍了使用JInternalFrame和一些按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用 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?

推荐答案

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

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

附录:正如@camickr建议的那样,技术上可以放一个 JButton 直接在 JDesktopPane 上,但实际上可能难以使用。

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.

这篇关于使用JInternalFrame和一些按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆