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

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", new AreaExclusiveOr());
    frame.pack();
    frame.setSize(new Dimension(400, 300));
    frame.setVisible(true);//from  w ww  . j av  a 2s. com
}

From source file:DateComboBoxRenderer.java

public static void main(String[] str) {
    JComboBox combo = new JComboBox();
    GregorianCalendar calendar = new GregorianCalendar();
    combo.addItem(calendar.getTime());/*from  w  ww  .j a  v a2  s .co  m*/

    calendar.roll(GregorianCalendar.DAY_OF_MONTH, 1);
    combo.addItem(calendar.getTime());

    combo.setRenderer(new DateComboBoxRenderer());

    JFrame frame = new JFrame();

    JPanel panel = new JPanel();
    panel.add(new JLabel("Date Combo: "));
    panel.add(combo);

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

From source file:ClipDemo.java

public static void main(String args[]) {
    JFrame mainFrame = new JFrame();
    mainFrame.getContentPane().add(new ClipDemo());
    mainFrame.pack();

    mainFrame.setVisible(true);/*from   ww  w. j a va2 s.  c om*/
}

From source file:Main.java

public static void main(String[] args) {
    JComboBox c = new JComboBox();
    c.addPopupMenuListener(new PopupMenuListener() {

        @Override//  w  w w.  j ava  2s .  c  o  m
        public void popupMenuCanceled(PopupMenuEvent e) {
            System.out.println(e.getSource());
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            System.out.println(e.getSource());
        }

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            System.out.println(e.getSource());
        }
    });
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().setLayout(new FlowLayout());
    f.getContentPane().add(c);
    f.pack();
    f.setVisible(true);
}

From source file:AreaIntersecting.java

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", new AreaIntersecting());
    frame.pack();
    frame.setSize(new Dimension(400, 300));
    frame.setVisible(true);/* ww w  .j  a v  a2s.co m*/
}

From source file:SimpleList2.java

public static void main(String s[]) {
    JFrame frame = new JFrame("List Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new SimpleList2());
    frame.pack();
    frame.setVisible(true);/*from www.  ja v a2  s .c o  m*/
}

From source file:Main.java

public static void main(String[] av) {
    JFrame frame = new JFrame();
    Container cp = frame.getContentPane();
    cp.add(new Main(new File(".")));
    frame.pack();
    frame.setVisible(true);//ww  w  .  j  a  va  2s.  co m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("");
    JLabel label = new JLabel("Move this window's title bar to demonstrate screen edge snapping.");
    frame.getContentPane().add(label);/*from   w  ww  .  j a  va 2  s  .  c  om*/
    frame.pack();

    frame.addComponentListener(new Main());
    frame.setVisible(true);
}

From source file:WindowSnapper.java

public static void main(String[] args) {
    JFrame frame = new JFrame("");
    JLabel label = new JLabel("Move this window's title bar to demonstrate screen edge snapping.");
    frame.getContentPane().add(label);/*ww  w. j ava  2 s.c  om*/
    frame.pack();

    frame.addComponentListener(new WindowSnapper());
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JButton close = new JButton("Close me programmatically");
    final JFrame f = new JFrame("Close Me");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(close);/*from   w w w  .  ja va 2  s  .  c o  m*/
    close.addActionListener(e -> {
        f.dispose();
    });
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}