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) {
    JPanel pane = newPane("Label in frame");
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(pane);//from ww w  . j a v a  2  s. c  o m
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

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

}

From source file:ricecompression.RiceCompression.java

/**
 * @param args the command line arguments
 *///from  ww  w. java 2s.co m
public static void main(String[] args) {
    RiceCompression rice = new RiceCompression();
    XYSeries data = new XYSeries("RICE");
    for (int i = -1023; i < 1024; i++) {
        String riceCode = rice.compress(32, i);
        data.add(i, riceCode.length());
    }
    XYSeriesCollection collection = new XYSeriesCollection(data);
    JFreeChart grafica = ChartFactory.createXYLineChart("RICE", "Nmero a codificar", "Longitud del codi Rice",
            collection, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    panel.add(new JTextField(10));
    panel.add(new JButton("button"));
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);/*from  www  . ja v a2s . c om*/
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowIconified(WindowEvent wEvt) {
            ((JFrame) wEvt.getSource()).dispose();
        }

        @Override
        public void windowDeactivated(WindowEvent wEvt) {
            ((JFrame) wEvt.getSource()).dispose();
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");

    jb.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            System.out.println("ItemEvent!");
        }//from   w  w  w  .  j  ava2  s  .c om
    });

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }
    });

    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 s[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.pack();
    frame.setVisible(true);//from ww  w  . ja v  a 2  s .  c  om
}

From source file:Main.java

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

From source file:Main.java

public static void main(String[] args) {
    String[] items = { "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" };
    JList<String> myJList = new JList(items) {
        @Override//  w ww . j av  a2  s .co  m
        protected void processMouseEvent(MouseEvent e) {
            int modifiers = e.getModifiers() | InputEvent.CTRL_MASK;
            int modifiersEx = e.getModifiersEx() | InputEvent.CTRL_MASK;
            MouseEvent myME = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), modifiers,
                    e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(),
                    e.isPopupTrigger(), e.getButton());
            super.processMouseEvent(myME);
        }
    };
    JFrame f = new JFrame();
    f.add(new JScrollPane(myJList));
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new Main());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);//from  www. j  av  a2  s. co  m
}

From source file:MainClass.java

public static void main(String[] args) {
    JButton jb = new JButton("Press Me");

    jb.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            System.out.println("ItemEvent!");
        }/*from   www  . ja v  a2  s.c o m*/
    });

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }
    });

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