Example usage for javax.swing JFrame setBounds

List of usage examples for javax.swing JFrame setBounds

Introduction

In this page you can find the example usage for javax.swing JFrame setBounds.

Prototype

public void setBounds(Rectangle r) 

Source Link

Document

The r.width or r.height values will be automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .

Usage

From source file:Main.java

public static void setPreferredGeometry(JFrame frame) {

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension frameSize = frame.getPreferredSize();
    Dimension screenSize = tk.getScreenSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }//  w  w  w. jav a2s. co m

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    Point p = new Point((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    Rectangle rect = new Rectangle(p, frameSize);
    frame.setBounds(rect);
}

From source file:SplashScreenTest.java

/**
 * This method displays a frame with the same image as the splash screen.
 *//*w  ww .ja  v  a  2s  . c o  m*/
private static void init2() {
    final Image img = Toolkit.getDefaultToolkit().getImage(splash.getImageURL());

    final JFrame splashFrame = new JFrame();
    splashFrame.setUndecorated(true);

    final JPanel splashPanel = new JPanel() {
        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, null);
        }
    };

    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    splashPanel.setLayout(new BorderLayout());
    splashPanel.add(progressBar, BorderLayout.SOUTH);

    splashFrame.add(splashPanel);
    splashFrame.setBounds(splash.getBounds());
    splashFrame.setVisible(true);

    new SwingWorker<Void, Integer>() {
        protected Void doInBackground() throws Exception {
            try {
                for (int i = 0; i <= 100; i++) {
                    publish(i);
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
            }
            return null;
        }

        protected void process(List<Integer> chunks) {
            for (Integer chunk : chunks) {
                progressBar.setString("Loading module " + chunk);
                progressBar.setValue(chunk);
                splashPanel.repaint(); // because img is loaded asynchronously
            }
        }

        protected void done() {
            splashFrame.setVisible(false);

            JFrame frame = new JFrame();
            frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("SplashScreenTest");
            frame.setVisible(true);
        }
    }.execute();
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Constructor to run this application in a stand-alone window.
 *
 * @param ownerFrame the frame the application will be displayed in
 * @throws S3ServiceException/*w  ww. j  ava 2s .  c  o  m*/
 */
public Uploader(JFrame ownerFrame, Properties standAloneArgumentProperties) throws S3ServiceException {
    this(false);
    this.ownerFrame = ownerFrame;
    this.standAloneArgumentProperties = standAloneArgumentProperties;

    init();

    ownerFrame.getContentPane().add(this);
    ownerFrame.setBounds(this.getBounds());
    ownerFrame.setVisible(true);
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Constructor to run this application in a stand-alone window.
 *
 * @param ownerFrame the frame the application will be displayed in
 * @throws S3ServiceException//from   www  . jav  a2 s.c o  m
 */
public Cockpit(JFrame ownerFrame) throws S3ServiceException {
    this();
    this.ownerFrame = ownerFrame;
    isStandAloneApplication = true;
    init();

    ownerFrame.getContentPane().add(this);
    ownerFrame.setBounds(this.getBounds());
    ownerFrame.setVisible(true);
}

From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java

private static void fetchMenuVisualData_JMenuBar(MenuVisualData menuData, Container menuObject,
        Container parent) throws Exception {
    if (parent != null) {
        menuData.m_menuBounds = CoordinateUtils
                .get(SwingUtilities.convertRectangle(menuObject, menuObject.getBounds(), parent));
    } else {//from  w ww .j ava2s. c  o m
        // image
        {
            JFrame frame = new JFrame();
            frame.setBounds(menuObject.getBounds());
            frame.setJMenuBar((JMenuBar) menuObject);
            frame.pack();
            prepareForPrinting(frame);
            try {
                menuData.m_menuImage = createComponentShot(menuObject);
            } finally {
                setVisible(frame, false);
                frame.dispose();
            }
        }
        // bounds
        menuData.m_menuBounds = CoordinateUtils.get(menuObject.getBounds());
    }
    // items
    fetchMenuVisualData_items(menuData, menuObject);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Constructor to run this application in a stand-alone window.
 *
 * @param ownerFrame the frame the application will be displayed in
 * @throws S3ServiceException/*from www  .  j a v a  2s  .  co  m*/
 */
public Cockpit(JFrame ownerFrame) throws S3ServiceException {
    this.ownerFrame = ownerFrame;
    isStandAloneApplication = true;
    init();

    ownerFrame.getContentPane().add(this);
    ownerFrame.setBounds(this.getBounds());
    //ownerFrame.setVisible(true);
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Constructor to run this application in a stand-alone window.
 *
 * @param ownerFrame the frame the application will be displayed in
 * @throws S3ServiceException/*  ww w.ja  va 2s .  com*/
 */
public CockpitLite(JFrame ownerFrame, Properties standAloneArgumentProperties) throws S3ServiceException {
    mCredentialProvider = new BasicCredentialsProvider();
    this.ownerFrame = ownerFrame;
    this.standAloneArgumentProperties = standAloneArgumentProperties;
    isStandAloneApplication = true;
    init();

    ownerFrame.getContentPane().add(this);
    ownerFrame.setBounds(this.getBounds());
    ownerFrame.setVisible(true);
}

From source file:phex.Main.java

/**
 * /*w w w . ja  va 2 s . c o  m*/
 */
private static void validateJavaVersion() {
    if (SystemUtils.isJavaVersionAtLeast(1.5f)) {
        return;
    }

    JFrame frame = new JFrame("Wrong Java Version");
    frame.setSize(new Dimension(0, 0));
    frame.setVisible(true);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension winSize = frame.getSize();
    Rectangle rect = new Rectangle((screenSize.width - winSize.width) / 2,
            (screenSize.height - winSize.height) / 2, winSize.width, winSize.height);
    frame.setBounds(rect);
    JOptionPane.showMessageDialog(frame,
            "Please use a newer Java VM.\n" + "Phex requires at least Java 1.5.0. You are using Java "
                    + SystemUtils.JAVA_VERSION + "\n" + "To get the latest Java release go to http://java.com.",
            "Wrong Java Version", JOptionPane.WARNING_MESSAGE);
    System.exit(1);
}