Example usage for javax.swing JFrame getPreferredSize

List of usage examples for javax.swing JFrame getPreferredSize

Introduction

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

Prototype

public Dimension getPreferredSize() 

Source Link

Document

Returns the preferred size of this container.

Usage

From source file:ShowOff.java

public static void main(String[] args) {
    try {/*ww w .j  a  va  2 s  .c  o  m*/
        String filename = "largeJava2sLogo.jpg";
        String message = "Java Source and Support";
        int split = 4;
        JFrame f = new JFrame();
        f.getContentPane().setLayout(new BorderLayout());
        ShowOff showOff = new ShowOff(filename, message, split);
        f.add(showOff, BorderLayout.CENTER);
        f.setSize(f.getPreferredSize());
        f.setResizable(false);
        f.setVisible(true);
    } catch (Exception e) {
        System.out.println(e);
        System.exit(0);
    }
}

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;
    }//from 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:UIUtilities.java

public static void setFrameLocationRelativeTo(JFrame f, Component c) {
    if (c == null) {
        // Setting the position of the dialog on the center of the screen
        // in 1.4 should be replaced by
        //             f.setLocationRelativeTo(null);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        f.setLocation((int) d.getWidth() / 2 - (int) f.getPreferredSize().getWidth() / 2,
                (int) d.getHeight() / 2 - (int) f.getPreferredSize().getHeight() / 2);
    }/*from w w w.jav  a 2 s  .c om*/
}

From source file:Main.java

public Main() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new MyPanel());
    frame.pack();/*from   w ww.  java2 s .  c  om*/
    frame.setMinimumSize(frame.getPreferredSize());
    frame.setVisible(true);
}

From source file:scheduler.benchmarker.manager.CreateCombinedSplineChart.java

private void createSubChart(ChartPanel chart) {
    JFrame frameGraph = new JFrame();
    frameGraph.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frameGraph.setForeground(new Color(76, 76, 76));
    frameGraph.setBackground(new Color(246, 244, 242));

    Dimension window = Toolkit.getDefaultToolkit().getScreenSize();
    if (window.width < 1074 && window.height < 800)
        frameGraph.setPreferredSize(new Dimension(window.width, window.height));
    else//from  ww w .jav a  2s  .co m
        frameGraph.setPreferredSize(new Dimension(1074, 800));

    frameGraph.setLocation((window.width - frameGraph.getPreferredSize().width) / 2,
            (window.height - frameGraph.getPreferredSize().height) / 2);
    frameGraph.setResizable(true);
    frameGraph.add(chart);
    frameGraph.pack();
    frameGraph.setVisible(true);
}

From source file:scheduler.benchmarker.manager.CreateSimpleSplineChart.java

private void createSubChart(ChartPanel chart) {
    JFrame frameGraph = new JFrame();//new JFrame("FINAL RULES ARRANGEMENT");
    frameGraph.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frameGraph.setForeground(new Color(76, 76, 76));
    frameGraph.setBackground(new Color(246, 244, 242));

    Dimension window = Toolkit.getDefaultToolkit().getScreenSize();
    if (window.width < 1074 && window.height < 800)
        frameGraph.setPreferredSize(new Dimension(window.width, window.height));
    else/*from  ww  w  .  j av a  2 s.c  o m*/
        frameGraph.setPreferredSize(new Dimension(1074, 800));

    frameGraph.setLocation((window.width - frameGraph.getPreferredSize().width) / 2,
            (window.height - frameGraph.getPreferredSize().height) / 2);
    frameGraph.setResizable(true);
    frameGraph.add(chart);
    frameGraph.pack();
    frameGraph.setVisible(true);
}