Java JComponent Size show(final JComponent component, final String windowTitle, final Dimension size)

Here you can find the source of show(final JComponent component, final String windowTitle, final Dimension size)

Description

Show the given component in it's own window.

License

Open Source License

Parameter

Parameter Description
component a parameter
windowTitle a parameter
size a parameter

Declaration

public static void show(final JComponent component, final String windowTitle, final Dimension size) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Main {
    /**/* w  w w . java  2  s.  c  om*/
     * Show the given component in it's own window. After closing the window the application keeps running. The window is opened asynchronously.
     * 
     * @param component
     * @param windowTitle
     * @param size
     */
    public static void show(final JComponent component, final String windowTitle, final Dimension size) {
        // Schedule a job for the event-dispatching thread:
        SwingUtilities.invokeLater(() -> showGUI(component, windowTitle, size));
    }

    private static JFrame showGUI(final JComponent newContentPane, final String windowTitle, final Dimension size) {
        // Create and set up the window.
        final JFrame frame = new JFrame(windowTitle);

        // Create and set up the content pane.
        newContentPane.setOpaque(true); // content panes must be opaque
        frame.setContentPane(newContentPane);

        // Display the window.
        if (size == null) {
            frame.pack();
        } else {
            frame.setSize(size);
        }
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        return frame;
    }
}

Related

  1. setSizeBasedOnResolution(final JComponent component)
  2. setSizes(JComponent[] components, final Dimension dimension)
  3. setSMPSizes(JComponent comp, Dimension d)
  4. setUnlimitedSize(JComponent component)
  5. setZeroMinimumSize(Component component)
  6. showComponent(JComponent component, Dimension size)
  7. showGUI(final JComponent newContentPane, final String windowTitle, final Dimension size)
  8. showStaticPage(final URI uri, final Dimension size, final Point location)
  9. sizeUniformly(JComponent... components)