Example usage for javax.swing JFrame pack

List of usage examples for javax.swing JFrame pack

Introduction

In this page you can find the example usage for javax.swing JFrame 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:ArcDemo2D.java

public static void main(String s[]) {
    JFrame f = new JFrame("");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from w  w w  .j av a 2 s  .co  m*/
        }
    });
    JApplet applet = new ArcDemo2D();
    f.getContentPane().add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.show();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setTitle("JLabel Test");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ImageIcon imageIcon = new ImageIcon("yourFile.gif");

    JLabel label = new JLabel("Mixed", imageIcon, SwingConstants.RIGHT);

    frame.add(label);/*ww w.j a  v a  2 s  .c o  m*/
    frame.pack();
    frame.setVisible(true);
}

From source file:com.google.code.facebook.graph.sna.applet.ImageEdgeLabelDemo.java

/**
* a driver for this demo//w  w  w. j  av a  2 s .c  o  m
*/
public static void main(String[] args) {
    JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    content.add(new ImageEdgeLabelDemo());
    frame.pack();
    frame.setVisible(true);
}

From source file:EditableComboBox.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Combo Box Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new EditableComboBox());
    frame.pack();
    frame.setVisible(true);/*from  www  .  j av  a2  s .co  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);/*from w  ww.jav a 2s  .  c  o  m*/
    frame.add(new JButton("1"));
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    gbl.columnWeights = new double[] { 0.0f, 1.0f, 2.0f };
    gbl.rowWeights = new double[] { 0.0f, 1.0f };

    frame.pack();
    frame.setVisible(true);
}

From source file:com.bluexml.side.build.tools.graph.JungConverter.java

public static void main(String[] args) {

    // Graph<V, E> where V is the type of the vertices 
    // and E is the type of the edges 
    Graph<Integer, String> g = new SparseMultigraph<Integer, String>();
    // Add some vertices. From above we defined these to be type Integer. 
    g.addVertex((Integer) 1);//from  w ww  .ja  v  a 2s.co m
    g.addVertex((Integer) 2);
    g.addVertex((Integer) 3);
    // Add some edges. From above we defined these to be of type String 
    // Note that the default is for undirected edges. 
    g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives 
    g.addEdge("Edge-B", 2, 3);
    // Let's see what we have. Note the nice output from the 
    // SparseMultigraph<V,E> toString() method 
    logger.debug("The graph g = " + g.toString());
    // Note that we can use the same nodes and edges in two different graphs. 
    Graph<Integer, String> g2 = new SparseMultigraph<Integer, String>();
    g2.addVertex((Integer) 1);
    g2.addVertex((Integer) 2);
    g2.addVertex((Integer) 3);
    g2.addEdge("Edge-A", 1, 3);
    g2.addEdge("Edge-B", 2, 3, EdgeType.DIRECTED);
    g2.addEdge("Edge-C", 3, 2, EdgeType.DIRECTED);
    g2.addEdge("Edge-P", 2, 3); // A parallel edge 
    logger.debug("The graph g2 = " + g2.toString());

    DirectedSparseMultigraph<MyNode, MyLink> g3 = new DirectedSparseMultigraph<MyNode, MyLink>();
    // Create some MyNode objects to use as vertices
    MyNode n1, n2, n3, n4, n5;
    n1 = new MyNode(1);
    n2 = new MyNode(2);
    n3 = new MyNode(3);
    n4 = new MyNode(4);
    n5 = new MyNode(5); // note n1-n5 declared elsewhere. 
    // Add some directed edges along with the vertices to the graph 
    g3.addEdge(new MyLink(2.0, 48), n1, n2, EdgeType.DIRECTED); // This method 
    g3.addEdge(new MyLink(2.0, 48), n2, n3, EdgeType.DIRECTED);
    g3.addEdge(new MyLink(3.0, 192), n3, n5, EdgeType.DIRECTED);
    g3.addEdge(new MyLink(2.0, 48), n5, n4, EdgeType.DIRECTED); // or we can use 
    g3.addEdge(new MyLink(2.0, 48), n4, n2); // In a directed graph the 
    g3.addEdge(new MyLink(2.0, 48), n3, n1); // first node is the source 
    g3.addEdge(new MyLink(10.0, 48), n2, n5);// and the second the destination
    logger.debug("The graph g3 = " + g3.toString());

    //SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here 
    // The Layout<V, E> is parameterized by the vertex and edge types 
    CircleLayout<MyNode, MyLink> layout = new CircleLayout<MyNode, MyLink>(g3);
    layout.setSize(new Dimension(300, 300)); // sets the initial size of the space 
    // The BasicVisualizationServer<V,E> is parameterized by the edge types 
    BasicVisualizationServer<MyNode, MyLink> vv = new BasicVisualizationServer<MyNode, MyLink>(layout);
    vv.setPreferredSize(new Dimension(350, 350)); //Sets the viewing area size 

    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);

}

From source file:AreaSubtract.java

public static void main(String s[]) {
    JFrame f = new JFrame("Pear");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from  w ww  . j a v a 2  s . co m
        }
    });
    JApplet applet = new AreaSubtract();
    f.getContentPane().add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(150, 200));
    f.show();
}

From source file:EllipseDemo2D.java

public static void main(String s[]) {
    JFrame f = new JFrame("");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from  ww w.j  a  v  a2s.com
        }
    });
    JApplet applet = new EllipseDemo2D();
    f.getContentPane().add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.show();
}

From source file:REDemo.java

/** "main program" method - construct and show */
public static void main(String[] av) {
    JFrame f = new JFrame("REDemo");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    REDemo comp = new REDemo();
    f.setContentPane(comp);/*  www .  j a  v a 2 s. co m*/
    f.pack();
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:NormSample.java

public static void main(String[] args) {

    // creating an applete for normalization

    JFrame f = new JFrame("Normalizer's API");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    NormSample applet = new NormSample();
    applet.init();/*from   ww w.j av a  2s.  c o m*/
    f.add("Center", applet);
    f.pack();
    f.setVisible(true);
}