Here you can find the source of setupWindowContentPane(final Window aWindow, final Component aCenterComponent, final Component aButtonPane, final JButton defaultButton)
Parameter | Description |
---|---|
aWindow | the window to setup, cannot be <code>null</code>; |
aCenterComponent | the component that should appear at the center of the dialog; |
aButtonPane | the component that should appear at the bottom of the dialog |
defaultButton | the default button for this dialog; can be null for "none". |
public static void setupWindowContentPane(final Window aWindow, final Component aCenterComponent, final Component aButtonPane, final JButton defaultButton)
//package com.java2s; /*//from w ww .j a va2s .c o m * OpenBench LogicSniffer / SUMP project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * * * Copyright (C) 2010-2011 - J.W. Janssen, http://www.lxtreme.nl */ import java.awt.*; import javax.swing.*; public class Main { private static final int DIALOG_PADDING = 6; /** * Sets up the given dialog's content pane by setting its border to provide a * good default spacer, and setting the content pane to the given components. * * @param aDialog * the dialog to setup, cannot be <code>null</code>; * @param aCenterComponent * the component that should appear at the center of the dialog; * @param aButtonPane * the component that should appear at the bottom of the dialog * (typically the buttons). */ public static void setupWindowContentPane(final Window aDialog, // final Component aCenterComponent, final Component aButtonPane) { setupWindowContentPane(aDialog, aCenterComponent, aButtonPane, null); } /** * Sets up the given window content pane by setting its border to provide a * good default spacer, and setting the content pane to the given components. * * @param aWindow * the window to setup, cannot be <code>null</code>; * @param aCenterComponent * the component that should appear at the center of the dialog; * @param aButtonPane * the component that should appear at the bottom of the dialog * @param defaultButton * the default button for this dialog; can be null for "none". * @see javax.swing.JRootPane#setDefaultButton(javax.swing.JButton) */ public static void setupWindowContentPane(final Window aWindow, final Component aCenterComponent, final Component aButtonPane, final JButton defaultButton) { final JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(BorderFactory.createEmptyBorder(DIALOG_PADDING, DIALOG_PADDING, // DIALOG_PADDING, DIALOG_PADDING)); contentPane.add(aCenterComponent, BorderLayout.CENTER); contentPane.add(aButtonPane, BorderLayout.PAGE_END); if (aWindow instanceof JDialog) { ((JDialog) aWindow).setContentPane(contentPane); ((JDialog) aWindow).getRootPane().setDefaultButton(defaultButton); } else if (aWindow instanceof JFrame) { ((JFrame) aWindow).setContentPane(contentPane); ((JFrame) aWindow).getRootPane().setDefaultButton(defaultButton); } aWindow.pack(); } }