Example usage for java.awt Frame pack

List of usage examples for java.awt Frame pack

Introduction

In this page you can find the example usage for java.awt Frame pack.

Prototype

@SuppressWarnings("deprecation")
public void pack() 

Source Link

Document

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

Usage

From source file:Main.java

public static void main(String[] args) {
    Frame f = new Main("BorderLayout demo");
    f.pack();
    f.setVisible(true);//from w  w w .j  a v a  2  s  .c  om
}

From source file:Main.java

public static void main(String args[]) {
    Frame f = new Frame();
    JPanel mgb = new Main();
    f.add("Center", mgb);
    f.pack();
    f.setSize(300, 300);//from  ww w  . j av a  2  s .  com
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    // Create a test frame
    Frame frame = new Frame("Hello");
    frame.add(new Label("Minimize demo"));
    frame.pack();

    // Show the frame
    frame.setVisible(true);/*w w  w  .  j  a v a  2  s.com*/

    // Sleep for 5 seconds, then minimize
    Thread.sleep(5000);
    frame.setState(Frame.ICONIFIED);
    frame.setVisible(false);
    // Sleep for 5 seconds, then restore
    Thread.sleep(5000);
    frame.setState(Frame.NORMAL);
    frame.setVisible(true);

    // Sleep for 5 seconds, then kill window
    Thread.sleep(5000);
    frame.setVisible(false);
    frame.dispose();

    // Terminate test
    System.exit(0);
}

From source file:MemImage.java

/**
 * Demo main program, showing two ways to use it. Create a small MemImage
 * and set it as this Frame's iconImage. Also display a larger version of
 * the same image in the Frame./*from   w  w  w .java2 s. com*/
 */
public static void main(String[] av) {
    Frame f = new Frame("MemImage.java");
    f.add(new MemImage());
    f.setIconImage(new MemImage(16, 16).getImage());
    f.pack();
    f.setVisible(true);
}

From source file:TexturedText.java

/** "main program" method - construct and show */
public static void main(String[] av) {
    // create a TexturedText object, tell it to show up
    final Frame f = new Frame("TexturedText");
    TexturedText comp = new TexturedText();
    f.add(comp);/*from  ww  w  .  j  a va 2  s .c o  m*/
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            f.setVisible(false);
            f.dispose();
            System.exit(0);
        }
    });
    f.pack();
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:ShapeMover.java

public static void main(String s[]) {
    Frame f = new Frame("ShapeMover");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*  ww w.  j av a 2 s .  c  o  m*/
        }
    });
    Applet applet = new ShapeMover();
    f.add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(550, 250));
    f.show();
}

From source file:Main.java

public static void main(String[] args) {
    Frame f = new Frame("FlowLayout demo");
    f.setLayout(new FlowLayout());
    f.add(new Button("Red"));
    f.add(new Button("Blue"));
    f.add(new Button("White"));
    List list = new List();
    for (int i = 0; i < args.length; i++) {
        list.add(args[i]);//from  w w w .j  ava  2 s  .c  om
    }
    f.add(list);
    f.add(new Checkbox("Pick me", true));
    f.add(new Label("Enter name here:"));
    f.add(new TextField(20));
    f.pack();
    f.setVisible(true);
}

From source file:WebCrawler.java

public static void main(String argv[]) {
    Frame f = new Frame("WebFrame");
    WebCrawler applet = new WebCrawler();
    f.add("Center", applet);

    /*    Behind a firewall set your proxy and port here!
    *//*from  w w w. j  a v  a2s . co  m*/
    Properties props = new Properties(System.getProperties());
    props.put("http.proxySet", "true");
    props.put("http.proxyHost", "webcache-cup");
    props.put("http.proxyPort", "8080");

    Properties newprops = new Properties(props);
    System.setProperties(newprops);
    /**/

    applet.init();
    applet.start();
    f.pack();
    f.show();
}

From source file:org.qsos.radar.GenerateRadar.java

/**
 * This class creates a composite in which the radar char will be
 * implemented/* www  .j  a v  a2  s . c  om*/
 * 
 * @param parent
 *             Composite where the chart will be seen
 * @param Categories
 *             String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize
 * @param Scores
 *             Double[] that contains the average score of each category
 * @return Control
 * 
 */
public static Control createChart(Composite parent, String[] Categories, double[] Scores) {

    Composite Charcomposite = new Composite(parent, SWT.EMBEDDED);
    Charcomposite.setLayout(new FillLayout());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //
    for (int i = 0; i < CatNumber; i++) {
        dataset.addValue(Scores[i], getTitle(), Categories[i]);
    }

    String BackGroundMire = null;

    //Configuration of the spiderwebplot
    SpiderWebPlot plot = new SpiderWebPlot();
    plot.setDataset(dataset);
    plot.setMaxValue(JQConst.RADAR_MAX_VALUE);
    plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT);
    plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP);
    plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT);
    plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP);
    plot.setWebFilled(true);

    //The backgroundpicture used as a spiderweb is chosen according to the 
    //number of categories selected
    switch (CatNumber) {
    case 4:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_4;
        break;
    case 5:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_5;
        break;
    case 6:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_6;
        break;
    case 7:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_7;
        break;
    }
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire);
    plot.setBackgroundImage(icon.getImage());

    //chart creation
    JFreeChart chart = new JFreeChart(plot);

    //Here the background color from the shell is taken in order to match AWT and SWT backgrounds
    Color backgroundColor = parent.getBackground();

    //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite
    java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite);
    chartPanel.setLayout(new java.awt.GridLayout());
    ChartPanel jfreeChartPanel = new ChartPanel(chart);

    chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    chartPanel.add(jfreeChartPanel);
    chartPanel.pack();

    return parent;

}

From source file:grafici.PazientiPieChart.java

/**
 * Default constructor./*from w ww  .jav a 2 s  . c o  m*/
 * 
 * @param title
 *            the frame title.
 */
public PazientiPieChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);
    titolo = title;
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));

    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}