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) {
    JPanel mainPanel = new JPanel();
    JTextField field = new JTextField(20);
    JTextField field1 = new JTextField(20);

    field.getDocument().addDocumentListener(new DocumentListener() {
        @Override//  ww  w.  j a v  a  2  s .c  om
        public void changedUpdate(DocumentEvent e) {
            updateLabel(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateLabel(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateLabel(e);
        }

        private void updateLabel(DocumentEvent e) {
            field1.setText(field.getText());
        }
    });

    mainPanel.setLayout(new GridLayout(1, 0, 10, 0));
    mainPanel.add(field);
    mainPanel.add(field1);

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

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setContentPane(new StringPanel());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);/*w  ww .  j  a v a 2s  .  c om*/
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(mainPanel);
    frame.pack();
    frame.setVisible(true);/*w  w w. java2 s.  co  m*/
}

From source file:SelectionMonitor.java

public static void main(String s[]) {

    JFrame frame = new JFrame("Selection Monitor");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new SelectionMonitor());
    frame.pack();
    frame.setVisible(true);/*w  ww . ja v a  2 s  .c  o  m*/

}

From source file:Main.java

public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main(), BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);//from  www  .j  a  va2 s .  c om
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(mainPanel);/*from   w  w  w  .  j ava 2 s .c o m*/
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:MainClass.java

public static void main(String args[]) {
    final MainClass it = new MainClass();

    JFrame frame = new JFrame("Progress Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(it);//  ww  w .  jav  a2 s  .  co m
    frame.pack();
    frame.setVisible(true);

    for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) {
        final int percent = i;
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    it.updateBar(percent);
                }
            });

            java.lang.Thread.sleep(100);

        } catch (Exception e) {
            ;
        }
    }
}

From source file:Main.java

public static void main(String args[]) {
    final Main it = new Main();

    JFrame frame = new JFrame("Progress Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(it);/* w w  w  .ja  va 2  s . c  o  m*/
    frame.pack();
    frame.setVisible(true);

    for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) {
        final int percent = i;
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    it.updateBar(percent);
                }
            });

            java.lang.Thread.sleep(100);

        } catch (Exception e) {
            ;
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main(BoxLayout.X_AXIS));
    frame.pack();
    frame.setVisible(true);//from   w w  w  . j a  va  2  s.co m
}

From source file:LineBreakMeasurerDemo.java

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", new DisplayPanel());
    frame.pack();
    frame.setSize(new Dimension(350, 400));
    frame.setVisible(true);//w  w  w  . j  ava2s  .com
}