Here you can find the source of wrapPanelInFrame(JFrame frame, JPanel panel, String caption, int width, int height)
public static JFrame wrapPanelInFrame(JFrame frame, JPanel panel, String caption, int width, int height)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { /** For your main window, you'll want to set this: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) * because we don't do that here. This method also sets the frame visible. *//* w w w . j a va 2s . c o m*/ public static JFrame wrapPanelInFrame(JPanel panel, String caption, int width, int height) { JFrame frame = new JFrame(caption); frame.setSize(width, height); frame.add(panel); //another way to do this: frame.getContentPane().add(panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); return frame; } public static JFrame wrapPanelInFrame(JFrame frame, JPanel panel, String caption, int width, int height) { frame.setTitle(caption); frame.setSize(width, height); frame.add(panel); //another way to do this: frame.getContentPane().add(panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); return frame; } }