public void init() { // 向内部窗口中添加组件 iframe.add(new JScrollPane(new JTextArea(8, 40))); desktop.setPreferredSize(new Dimension(400, 300)); // 把虚拟桌面添加到JFrame窗口中 jf.add(desktop); // 设置内部窗口的大小、位置 iframe.reshape(0, 0, 300, 200); // 显示并选中内部窗口 iframe.show(); desktop.add(iframe); JPanel jp = new JPanel(); deskBn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 弹出内部对话框,以虚拟桌面作为父组件 JOptionPane.showInternalMessageDialog(desktop, "属于虚拟桌面的对话框"); } }); internalBn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 弹出内部对话框,以内部窗口作为父组件 JOptionPane.showInternalMessageDialog(iframe, "属于内部窗口的对话框"); } }); jp.add(deskBn); jp.add(internalBn); jf.add(jp, BorderLayout.SOUTH); jf.pack(); jf.setVisible(true); }
/** @see javax.swing.JInternalFrame#reshape(int, int, int, int) */ public void reshape(int x, int y, int width, int height) { super.reshape(x, y, width, height); target.reshape(x, y, width, height); }