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

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

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");
    System.out.println(jb.getHorizontalAlignment() == SwingConstants.LEFT);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);/*from   w  w  w  . j  a va  2 s.  c o  m*/
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new Main());
    f.pack();
    f.setVisible(true);//from w  ww.  j  av a  2  s  . c  om
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new TextBoundaryFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.show();/*from   w ww .j  a  v  a2 s  .c  om*/
}

From source file:MainClass.java

public static void main(String[] args) {
    JTextField field = new JTextField(30);

    ((AbstractDocument) (field.getDocument())).setDocumentFilter(new DocumentFilter() {
        public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
                throws BadLocationException {
            System.out.println("insert");
            fb.insertString(offset, string.toUpperCase(), attr);
        }/*from   ww  w  . ja va  2 s  . co m*/

        public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr)
                throws BadLocationException {
            System.out.println("replace");
            fb.replace(offset, length, string.toUpperCase(), attr);
        }
    });

    JFrame frame = new JFrame("User Information");
    frame.getContentPane().add(field);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

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

    frame.pack();
    frame.setVisible(true);/* w w w.j a  v  a  2s . c  om*/

    JButton btnGetSelectedText = new JButton("Get selected text");
    btnGetSelectedText.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println(jTextPane.getSelectedText());
        }
    });
    frame.getContentPane().add(jTextPane, BorderLayout.NORTH);
    frame.getContentPane().add(btnGetSelectedText, BorderLayout.SOUTH);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setSelected(true);/*ww w.  j  a va 2 s . co  m*/
    System.out.println(jb.isBorderPainted());

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

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setSelected(true);//from   w ww .  j  a  v a2 s  .c o m
    System.out.println(jb.getIcon());

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

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setSelected(true);/*  w w w.  j  ava2s .co m*/
    System.out.println(jb.isContentAreaFilled());

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

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setSelected(true);/*from ww w.j ava2 s.co m*/
    System.out.println(jb.isSelected());

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