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:bigdata.explorer.nutch.grapview.ShowLayouts.java

public static void main(String[] args) throws IOException {
    JPanel jp = getGraphPanel();//from ww w.j ava  2  s  . c o m

    JFrame jf = new JFrame();
    jf.getContentPane().add(jp);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.pack();
    jf.setVisible(true);
}

From source file:Main.java

public static void main(String argv[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String testStr = "Paste text here.";
    JTextArea wrapArea = new JTextArea(testStr, 20, 40);
    wrapArea.setLineWrap(true);/*w w  w .  ja v  a  2  s.c o  m*/
    wrapArea.setWrapStyleWord(true);
    wrapArea.setCaretPosition(testStr.length());
    frame.add(new JScrollPane(wrapArea));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setResizable(false);//  ww w .j a va2  s .  c  om
    JTextArea textArea = new JTextArea(25, 30);

    JScrollPane textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    window.add(textScroll);
    window.pack();
    window.setVisible(true);
}

From source file:FtfInputVerifier.java

public static void main(String argv[]) {

    java.net.URL u = null;//from  www . java  2s  .  co  m
    try {
        u = new java.net.URL("http://www.ora.com/");
    } catch (java.net.MalformedURLException ignored) {
    }

    // create two identical JFormattedTextFields
    JFormattedTextField ftf1 = new JFormattedTextField(u);
    JFormattedTextField ftf2 = new JFormattedTextField(u);

    // and set an InputVerifier on one of them
    ftf2.setInputVerifier(new InputVerifier() {
        public boolean verify(JComponent input) {
            if (!(input instanceof JFormattedTextField))
                return true; // give up focus
            return ((JFormattedTextField) input).isEditValid();
        }
    });

    JPanel p = new JPanel(new java.awt.GridLayout(0, 2, 3, 8));
    p.add(new JLabel("plain JFormattedTextField:", JLabel.RIGHT));
    p.add(ftf1);
    p.add(new JLabel("FTF with InputVerifier:", JLabel.RIGHT));
    p.add(ftf2);
    p.add(new JLabel("plain JTextField:", JLabel.RIGHT));
    p.add(new JTextField(u.toString()));
    p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    JFrame f = new JFrame("FtfInputVerifier");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JLabel("Try to delete the colon in each field.", JLabel.CENTER),
            java.awt.BorderLayout.NORTH);
    f.getContentPane().add(p, java.awt.BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
}

From source file:DoubleColor.java

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

    JColorChooser left = new JColorChooser();
    left.setDragEnabled(true);// ww  w.j a v  a2 s. c  o  m
    frame.add(left, BorderLayout.WEST);
    JColorChooser right = new JColorChooser();
    right.setDragEnabled(true);
    frame.add(right, BorderLayout.EAST);

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

From source file:com.lcdfx.pipoint.PiPoint.java

public static void main(final String[] args) throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, UnsupportedLookAndFeelException {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new PiPoint(args);
            frame.setTitle(APPLICATION_NAME);
            frame.setIconImage(/*from w  w w.  j a  va  2  s  .  c o  m*/
                    new ImageIcon(PiPoint.class.getResource("/resources/pipoint_icon.png")).getImage());
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    URL url = new URL("http://www.java2s.com/style/download.png");
    Image image = ImageIO.read(url);

    ImagePanel ip = new ImagePanel(new GridLayout(4, 4, 20, 20));
    ip.setPreferredSize(new Dimension(640, 480));
    f.setContentPane(ip);//from   ww  w  . j  a  v a 2s  .c o m
    f.pack();
    f.setVisible(true);

    ip.setImage(new ImageIcon(image));
}

From source file:JLabelDragSource.java

public static void main(String[] args) {
    try {/*  www .  ja v a2  s . c o m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new JFrame("Draggable JLabel");
    JLabel label = new JLabel("Drag this text", JLabel.CENTER);
    label.setFont(new Font("Serif", Font.BOLD, 32));
    f.getContentPane().add(label);
    f.pack();
    f.setVisible(true);

    // Attach the drag source
    JLabelDragSource dragSource = new JLabelDragSource(label);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String[] selections = { "green", "red", "orange", "dark blue" };
    JList list = new JList(selections);
    list.setSelectedIndex(1);//from  w w  w  .ja va 2s. c  o  m
    System.out.println(list.getSelectedValue());
    frame.add(new JScrollPane(list));
    frame.pack();

    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JComponent newContentPane = new Main();
    newContentPane.setOpaque(true);/* w  ww  . ja v  a  2s  .co  m*/
    frame.setContentPane(newContentPane);
    frame.pack();
    frame.setVisible(true);
}