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

public static void main(String[] args) {
    JTextArea ta = new JTextArea(20, 20);
    ((AbstractDocument) ta.getDocument()).setDocumentFilter(new MyFilter());

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(ta));
    frame.pack();
    frame.setVisible(true);/*from www. j a  va2  s . c  om*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final String title = "Testing: \u30CD";

    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JLabel label = new JLabel(title);
    label.setSize(200, 100);//from   w  ww .ja v a 2s.c  o m
    frame.setContentPane(label);
    frame.pack();
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            JScrollPane scrollpane = new JScrollPane(new ScrollPaneArtifacts());
            scrollpane.getViewport().setPreferredSize(new Dimension(400, 400));
            JFrame frame = new JFrame("ScrollPaneArtifacts");
            frame.getContentPane().add(scrollpane);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);//  w  w  w  . ja v  a2 s .  co m
        }
    });
}

From source file:Main.java

public static void main(final String[] args) {
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.getContentPane().setBackground(Color.red);
    frame.setPreferredSize(new Dimension(400, 300));
    frame.pack();
    frame.setVisible(true);//from   w ww .j  a v  a 2 s.co m
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();

    JPanel centeredPanel = new JPanel();
    centeredPanel.add(new JButton("one"));
    centeredPanel.add(new JButton("two"));

    f.getContentPane().add(centeredPanel);
    f.pack();
    f.setVisible(true);/* w w  w. jav a 2  s  .c  om*/
}

From source file:com.rest.samples.getImagePrintJPanel.java

public static void main(String[] args) {
    // TODO code application logic here
    String url = "https://api.adorable.io/avatars/eyes5";
    try {/*from w ww  . ja v  a2  s .  c om*/
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet getMethod = new HttpGet(url);
        getMethod.addHeader("accept", "application/png");
        HttpResponse res = hc.execute(getMethod);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        InputStream is = res.getEntity().getContent();

        Image image = ImageIO.read(is);
        JFrame frame = new JFrame();
        JLabel label = new JLabel(new ImageIcon(image));
        frame.getContentPane().add(label, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Main.java

public static void main(String[] args) {
    final JTextPane tp = new JTextPane();
    JButton withFocus = new JButton("Select with focus");
    tp.addMouseListener(new MouseAdapter() {

        @Override// www  .j  a  v  a2  s .  c o  m
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                tp.selectAll();
            }
        }

    });

    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(tp));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DefaultTableModel model = new DefaultTableModel(null, new String[] { "CheckMe", "Value" }) {
        public Class getColumnClass(int c) {
            switch (c) {
            case 0:
                return Boolean.class;
            default:
                return String.class;
            }/*from w  w w . j a  va  2  s  .c om*/
        }
    };
    JTable table = new JTable(model);
    JFrame frame = new JFrame("CheckBox Test");
    frame.add(table);
    model.addRow(new Object[] { true, "This is true" });
    model.addRow(new Object[] { false, "This is false" });
    frame.pack();
    frame.validate();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final int width = 512;
    final int height = 512;
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics g = img.getGraphics();
    g.setColor(Color.black);//from  w w w. jav a2 s  .co  m
    g.fillRect(0, 0, width, height);
    g.setColor(Color.white);
    final double A = 8;
    final double B = 0.5;
    final double N = 4;
    final double scale = 128;
    final double zoom = 50;
    final double step = 1 / scale;
    Point last = null;
    final Point origin = new Point(width / 2, height / 2);

    for (double t = 0; t <= 2 * Math.PI; t += step) {
        final double r = zoom * polarFunction(t, A, B, N);
        final int x = (int) Math.round(r * Math.cos(t));
        final int y = (int) Math.round(r * Math.sin(t));
        Point next = new Point(x, y);
        if (last != null) {
            g.drawLine(origin.x + last.x, origin.y + last.y, origin.x + next.x, origin.y + next.y);
        }
        last = next;
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new JLabel(new ImageIcon(img)));
    frame.pack();
    frame.setVisible(true);
}

From source file:JFramePack.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setTitle("My First Swing Application");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Welcome");
    frame.add(label);//from  w w w .  ja v a2s.  c o m
    frame.pack();
    frame.setVisible(true);
}