Java tutorial
//package com.java2s; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JComponent; import javax.swing.JDesktopPane; import javax.swing.JInternalFrame; public class Main { /** * Shows a specified JInternalFrame in the middle of the specified JDesktopPane. <br /> * The size of the JInternalFrame will be <code>frameSize</code>. <br /> * The frame is <i>just</i> closeable. <br /> * * @param desktop the JDesktopPane * @param frm the JInternalFrame * @param content the component which will be added to the JInternalFrame * @param frameSize the size of the JInternalFrame */ public static void showInternalFrame(JDesktopPane desktop, JInternalFrame frm, JComponent content, Dimension frameSize) { frm.setClosable(true); frm.setLayout(new BorderLayout()); frm.add(content, BorderLayout.CENTER); frm.setSize(frameSize); frm.setVisible(true); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); desktop.add(frm, 0); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } } /** * Creates (and displays) a JInternalFrame for a specified component. <br /> * The size of the JInternalFrame will be <code>frameSize</code>. <br /> * The frame is <i>just</i> closeable. <br /> * * @param desktop the JDesktopPane * @param comp the component to display in the created frame * @param title the title of the frame * @param frameSize the size of the frame * @return the created and displayed frame */ public static JInternalFrame showInternalFrame(JDesktopPane desktop, JComponent comp, String title, Dimension frameSize) { JInternalFrame frm = new JInternalFrame(title); frm.setClosable(true); frm.setLayout(new BorderLayout()); frm.add(comp, BorderLayout.CENTER); frm.setSize(frameSize); frm.setVisible(true); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); desktop.add(frm, 0); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } return frm; } /** * Creates (and displays) a JInternalFrame for a specified component. <br /> * The size of the JInternalFrame will be setted with calling <code>pack()</code>. <br /> * * @param desktop the JDesktopPane * @param comp the component to display in the created frame * @param title the title of the frame * @param frameSize the size of the frame * @return the created and displayed frame */ public static JInternalFrame showInternalFrame(JDesktopPane desktop, JComponent comp, String title) { JInternalFrame frm = new JInternalFrame(title); frm.setClosable(true); frm.setLayout(new BorderLayout()); frm.add(comp, BorderLayout.CENTER); desktop.add(frm, 0); frm.pack(); frm.setVisible(true); Dimension size = frm.getSize(); frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2); try { frm.setSelected(true); } catch (java.beans.PropertyVetoException e) { } return frm; } }