Using JInternalFrame and some button

Can I use JInternalFamewith a button in the main frame? The frame contains JDesktopPane, of course. The button should open JInternalFrameHow?

+1
source share
2 answers

I do not know how to place JButtondirectly on JDesktopPane, but you can use the menu items to create and select JInternalFrame. In this example, each menu item uses the Actionone defined in JInternalFrameto 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 can technically be put JButtondirectly on JDesktopPane, but it can be difficult to put into practice.

+6
source

, .

a) JInternalFrme , ,

b) JButton ,

Swing tutorial . " " " ".

, SSCCE, , .

+2

All Articles