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 s[]) {
    JFrame frame = new JFrame("Combo Box Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.pack();
    frame.setVisible(true);/*w  w w  .  j  a  v a 2 s  .co m*/
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Main newContentPane = new Main();
    newContentPane.setOpaque(true);/*from w w w . ja va  2s .  c o m*/
    f.setContentPane(newContentPane);

    f.pack();
    f.setVisible(true);
}

From source file:SwingWorkerExample.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(1);/* w  ww . j a  v a  2  s  .  co  m*/
    f.add(new SwingWorkerExample());
    f.pack();
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Combo Box Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MainClass());
    frame.pack();
    frame.setVisible(true);//from www  .j  av  a 2s  . com
}

From source file:Main.java

public static void main(String[] args) {
    Object[][] rowData = { { "Hello", "World" } };
    Object[] columnNames = { "A", "B" };

    JTable table;/*from w  ww .  java 2  s .c  o m*/
    DefaultTableModel model;

    model = new DefaultTableModel(rowData, columnNames);
    table = new JTable();
    table.setModel(model);
    JButton add = new JButton("Add");

    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            model.addRow(rowData[0]);
        }
    });
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = f.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(add, BorderLayout.SOUTH);
    c.add(new JScrollPane(table), BorderLayout.CENTER);

    f.pack();

    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final MaskFormatter formatter = new TimeFormatter();
    formatter.setValueClass(java.util.Date.class);
    final JFormattedTextField tf2 = new JFormattedTextField(formatter);
    tf2.setValue(new Date());
    final JLabel label = new JLabel();
    JButton bt = new JButton("Show Value");
    bt.addActionListener(e -> {//from w  w w .  ja va 2  s.c om
        System.out.println(" value 2 = " + tf2.getValue());
        System.out.println(" value 2 = " + tf2.getText());
        System.out.println("value class: " + formatter.getValueClass());
        label.setText(tf2.getText());
    });
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new GridLayout());
    f.getContentPane().add(tf2);
    f.getContentPane().add(label);
    f.getContentPane().add(bt);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:de.codesourcery.planning.DateAxisTestTool.java

public static void main(String[] args) {

    axis.setStartDate(DateUtils.round(new Date(), Calendar.DAY_OF_MONTH));
    axis.setRange(Duration.weeks(1));
    axis.setTickDuration(Duration.oneDay());

    JFrame frame = new JFrame();
    frame.getContentPane().add(new DateCanvas());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);// w  w w  .  ja  v  a 2  s.  co  m
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    final JTree tree = new JTree(getTreeModel());
    tree.setCellRenderer(new MyTreeCellRenderer());
    HyperlinkMouseListener listener = new HyperlinkMouseListener(tree);
    tree.addMouseListener(listener);//  w  w  w  . jav  a2s .  c o  m
    tree.addMouseMotionListener(listener);
    JFrame f = new JFrame(Main.class.getSimpleName());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JScrollPane(tree), BorderLayout.CENTER);
    f.pack();
    f.setSize(f.getWidth() + 100, f.getHeight() + 100);
    f.setVisible(true);
}

From source file:IsEDTExample.java

public static void main(String[] a) {
    JFrame f = new JFrame("Is Event Dispatch Thread Example");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new IsEDTExample());
    f.pack();
    f.setVisible(true);/*ww w .  j a v a 2  s. c om*/
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    JSpinner jspinner = makeDigitsOnlySpinnerUsingDocumentFilter();
    frame.getContentPane().add(jspinner, BorderLayout.CENTER);
    frame.getContentPane().add(new JButton("just another widget"), BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);/*  w  w w. j  av  a  2s . com*/
}