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:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Double Color Choosers");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JColorChooser left = new JColorChooser();
    left.setDragEnabled(true);//from  w ww .jav  a 2s .com
    frame.add(left, BorderLayout.WEST);

    JColorChooser right = new JColorChooser();
    right.setDragEnabled(true);
    frame.add(right, BorderLayout.EAST);

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

}

From source file:Sketch.java

public static void main(String[] args) {
    UIManager.put(JogShuttleUI.UI_CLASS_ID, "BasicJogShuttleUI");
    Sketch s = new Sketch();
    JFrame frame = new JFrame("Sample Sketch Application");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(s);//from w w  w .ja va 2 s .  co m
    frame.pack();
    frame.setVisible(true);
}

From source file:ega.projekt.graphDraw.DrawGraph.java

/**
 * @param args the command line arguments
 *//*from   w  w w  .  j a v  a  2s .com*/
public static void main(String[] args) {
    ega.projekt.graph.Graph dataGraph = new ega.projekt.graph.Graph(5, 100, 295, 295);
    if (dataGraph.getEdges().isEmpty())
        System.out.println("Error initializing graph");
    DrawGraph graphView = new DrawGraph(dataGraph); // This builds the graph
    // Layout<V, E>, VisualizationComponent<V,E>
    Layout<Node, Edge> layout = new StaticLayout(graphView.drawGraph);
    for (Node n : graphView.drawGraph.getVertices()) {
        layout.setLocation(n, new java.awt.geom.Point2D.Double(n.getX(), n.getY()));
    }
    layout.setSize(new Dimension(300, 300));
    BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<>(layout);
    vv.setPreferredSize(new Dimension(350, 350));
    // Setup up a new vertex to paint transformer...
    Transformer<Node, Paint> vertexPaint = new Transformer<Node, Paint>() {
        public Paint transform(Node i) {
            return Color.GREEN;
        }
    };

    // Set up a new stroke Transformer for the edges
    //float dash[] = {10.0f};
    final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    Transformer<Edge, Stroke> edgeStrokeTransformer = new Transformer<Edge, Stroke>() {
        public Stroke transform(Edge e) {
            if (e.isMarked()) {
                final Stroke modStroke = new BasicStroke(5.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
                return modStroke;
            }
            return edgeStroke;
        }
    };
    Transformer<Edge, Paint> edgePaint = new Transformer<Edge, Paint>() {
        public Paint transform(Edge e) {
            if (e.isMarked()) {
                return Color.RED;
            }
            return Color.BLACK;
        }
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<Node, Edge>());
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Edge, String>() {
        public String transform(Edge e) {
            return (e.getFlowString() + "/" + Integer.toString(e.getCapacity()));
        }
    });
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<Node, String>() {
        public String transform(Node n) {
            return (Integer.toString(n.getID()));
        }
    });
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

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

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Line Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border thinBorder = LineBorder.createBlackLineBorder();

    JButton thinButton = new JButton("1 Pixel");
    thinButton.setBorder(thinBorder);/*from  www.  j a  v  a  2 s  . com*/

    Container contentPane = frame.getContentPane();
    contentPane.add(thinButton, BorderLayout.NORTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Line Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border thickBorder = new LineBorder(Color.WHITE, 12);

    JButton thickButton = new JButton("12 Pixel");
    thickButton.setBorder(thickBorder);// w  w w  . jav  a2  s . co m

    Container contentPane = frame.getContentPane();
    contentPane.add(thickButton, BorderLayout.NORTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);//from   w  w w.j ava 2s .c  om
    JTabbedPane tabs = new JTabbedPane();
    tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    for (int i = 0; i < 5; i++) {
        tabs.addTab("Tab" + i, new TabPanel());
    }

    frame.add(tabs);
    frame.pack();
    frame.setVisible(true);

}

From source file:Clock.java

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

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    JTextField tField = new JTextField(10);
    ((AbstractDocument) tField.getDocument()).setDocumentFilter(new MyDocumentFilter());
    contentPane.add(tField);/*from  w  w w  . j  a va  2 s  .com*/

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

From source file:JListTest.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("JList Test");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String[] selections = { "green", "red", "orange", "dark blue" };
    JList list = new JList(selections);
    list.setSelectedIndex(1);/*from   ww w  . j ava 2s.  c o  m*/
    System.out.println(list.getSelectedValue());
    frame.add(new JScrollPane(list));
    frame.pack();

    frame.setVisible(true);
}