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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…