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) {
    JFrame frame = new JFrame("");
    frame.pack();

    frame.addComponentListener(new Main());
    frame.setVisible(true);//from  w w w.j  av  a  2 s  .c o  m
}

From source file:DrawStringDemo.java

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

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

From source file:Main.java

public static void main(String[] args) {
    JComboBox<String> my = new JComboBox<>(new String[] { "HELLO WORLD", "java2s.com" });
    JFrame frame = new JFrame("");
    frame.add(my);//  w  ww.ja va  2 s.  c o m
    frame.pack();
    frame.setVisible(true);
    my.setSelectedIndex(1);
}

From source file:Main.java

public static final void main(String[] args) throws Exception {
    JFrame frame = new Main();
    frame.pack();
    frame.setVisible(true);/*w w  w .  java 2s  .co  m*/
}

From source file:FlowLayoutExample.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    JTextArea area = new JTextArea("text area");
    area.setPreferredSize(new Dimension(100, 100));

    JButton button = new JButton("button");
    panel.add(button);//from ww  w. ja  v  a  2 s.c  om

    panel.add(new JScrollPane(area));

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JButton component = new JButton("a");
    component.addFocusListener(new MyFocusListener());

    JFrame f = new JFrame();
    f.add(component);/*www  . ja  v  a 2s . c  o m*/
    f.pack();
    f.setVisible(true);

}

From source file:BorderExample.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new BorderLayout());
    JPanel top = new JPanel();

    top.setBackground(Color.gray);
    top.setPreferredSize(new Dimension(250, 150));
    panel.add(top);/*from  w w  w . ja va2s.  c  om*/

    panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40)));
    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

}

From source file:MyLabel.java

public static void main(String[] args) {
    String lyrics = "<html>Line<br>line<br>line</html>";

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));

    JLabel label = new JLabel(lyrics);
    label.setFont(new Font("Georgia", Font.PLAIN, 14));
    label.setForeground(new Color(50, 50, 25));

    panel.add(label, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    JFrame f = new JFrame();
    f.add(panel);/*  ww w.  j  ava  2 s .co  m*/
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JTable table = new JTable(22, 5);
    table.setPreferredScrollableViewportSize(new Dimension(400, 300));
    final JScrollPane scrollPane = new JScrollPane(table);
    JButton cornerButton = new JButton("#");
    scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, cornerButton);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    JFrame frame = new JFrame();
    frame.add(scrollPane);//from   ww w  .j  a  v a2  s  .c  o  m
    frame.pack();
    frame.setVisible(true);
}

From source file:RigidArea.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(new EmptyBorder(new Insets(40, 60, 40, 60)));

    panel.add(new JButton("Button"));
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(new JButton("Button"));
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(new JButton("Button"));
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(new JButton("Button"));

    JFrame f = new JFrame();
    f.add(panel);/*ww  w .  ja v  a 2s .  c  om*/
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}