Java – use jinternalframe and some buttons

Can we use jinternalfame with buttons in the main frame? Of course, the framework contains jdesktopane How about this button should open jinternalframe?

Solution

I don't know how to put JButton directly on the jdesktoppane, but you can use the menu item to create and select jinternalframe In this example, each menu item uses the action defined in 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; }
}

Appendix: as @camickr said, JButton can be put directly on jdesktoppane technically, but it may be difficult to use in practice

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>