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(String[] argv) {
    MainClass panel = new MainClass();
    JFrame frame = new JFrame("Arabic Digits");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", panel);
    frame.pack();
    frame.setVisible(true);/*from   ww  w  . ja  va  2  s  . c  o  m*/
}

From source file:Main.java

public static void main(final String[] av) {
    JFrame frame = new JFrame();
    Container cp = frame.getContentPane();
    cp.add(new Main(new File(".")));
    frame.pack();
    frame.setVisible(true);/* w ww  .  java  2  s .  c om*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:GridLayoutDemo.java

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

    addComponentsToPane(frame.getContentPane());

    frame.pack();
    frame.setVisible(true);//from  ww  w .  j  av a  2 s. c o  m
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new Main());
    frame.pack();
    frame.setVisible(true);/*from  ww  w .  j  a  v  a 2  s  .  c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new Main());
    frame.pack();
    frame.setSize(400, 125);/*from www .  java2  s . c om*/
    frame.setVisible(true);
}

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.setLocationByPlatform(true);/*  ww w  . java 2  s.c om*/
    frame.setVisible(true);
}

From source file:MyCanvas.java

public static void main(String args[]) {
    JFrame mainFrame = new JFrame("Graphics demo");
    mainFrame.getContentPane().add(new MyCanvas());
    mainFrame.pack();
    mainFrame.setVisible(true);/*w w w  . j a  va2 s  . c o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    int TIMER_DELAY = 2000;
    String[] data = { "A", "B", "C", "D" };

    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(data);

    JComboBox<String> combobox = new JComboBox<>(model);
    JList<String> jlist = new JList<>(model);

    new Timer(TIMER_DELAY, new ActionListener() {
        private int count = 0;

        public void actionPerformed(ActionEvent e) {
            model.addElement("count: " + count);
            count++;/*w ww. j  av  a2s.  com*/
        }
    }).start();

    JPanel comboPanel = new JPanel();
    comboPanel.add(combobox);

    JPanel listPanel = new JPanel();
    listPanel.add(new JScrollPane(jlist));

    JPanel panel = new JPanel(new GridLayout(1, 0));
    panel.add(comboPanel);
    panel.add(listPanel);
    panel.setPreferredSize(new Dimension(400, 200));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(panel);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("Text Field Elements");
    JTextField tf = new JTextField(32);
    tf.setText("That's one small step for man...");
    f.getContentPane().add(tf);/*  w  ww  .ja v a2  s  .co m*/
    f.pack();
    f.setVisible(true);

    ((AbstractDocument) tf.getDocument()).dump(System.out);
}

From source file:MainClass.java

public static void main(String s[]) {
    JFrame frame = new JFrame("List Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MainClass());
    frame.pack();
    frame.setVisible(true);//  w  ww  . jav  a  2 s  .  c o m
}