Example usage for javax.swing JFrame JFrame

List of usage examples for javax.swing JFrame JFrame

Introduction

In this page you can find the example usage for javax.swing JFrame JFrame.

Prototype

public JFrame(String title) throws HeadlessException 

Source Link

Document

Creates a new, initially invisible Frame with the specified title.

Usage

From source file:WindowTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Window Listener");
    WindowListener listener = new WindowListener() {
        public void windowActivated(WindowEvent w) {
            System.out.println(w);
        }//from ww w  .  ja  va  2 s .c om

        public void windowClosed(WindowEvent w) {
            System.out.println(w);
        }

        public void windowClosing(WindowEvent w) {
            System.out.println(w);
            System.exit(0);
        }

        public void windowDeactivated(WindowEvent w) {
            System.out.println(w);
        }

        public void windowDeiconified(WindowEvent w) {
            System.out.println(w);
        }

        public void windowIconified(WindowEvent w) {
            System.out.println(w);
        }

        public void windowOpened(WindowEvent w) {
            System.out.println(w);
        }
    };
    frame.addWindowListener(listener);
    frame.setSize(300, 300);
    frame.show();
}

From source file:FormattedTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Formatted");
    Container contentPane = frame.getContentPane();
    JFormattedTextField ftf1 = new JFormattedTextField(new Integer(0));
    contentPane.add(ftf1, BorderLayout.NORTH);
    JFormattedTextField ftf2 = new JFormattedTextField(new Date());
    contentPane.add(ftf2, BorderLayout.SOUTH);
    frame.setSize(200, 100);/*  w  w  w . j  a v  a 2s. c  o m*/
    frame.show();
}

From source file:TabbedPaneTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JTabbedPane");
    final Container contentPane = frame.getContentPane();
    JTabbedPane jtp = new JTabbedPane();
    contentPane.add(jtp, BorderLayout.CENTER);
    for (int i = 0; i < 5; i++) {
        JButton button = new JButton("Card " + i);
        jtp.add("Btn " + i, button);
    }//from   ww  w  . j a va  2  s  .  c  o m
    frame.setSize(300, 200);
    frame.show();
}

From source file:AddingRemovingJMenu.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);/*  w  w  w. j  a  va  2 s  . co m*/

    JMenu editMenu = new JMenu("Edit");
    menuBar.add(editMenu);

    menuBar.remove(0);

    menuBar.revalidate();

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String title = "GridBagLayout";
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridBagLayout());

    for (int i = 1; i <= 9; i++) {
        contentPane.add(new JButton("Button  " + i));
    }/*w ww . j  a  v a 2s .c o  m*/
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JProgressBar Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JProgressBar progressBar = new JProgressBar();
    progressBar.setValue(25);/* www  .ja  va2s .c  o m*/
    progressBar.setStringPainted(true);
    Border border = BorderFactory.createTitledBorder("Reading...");
    progressBar.setBorder(border);
    f.add(progressBar, BorderLayout.NORTH);
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:TableSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JTable Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    Object rows[][] = { { "AMZN", "Amazon", "67 9/16" }, { "AOL", "America Online", "68 3/4" },
            { "BOUT", "About.com", "56 3/8" }, { "CDNW", "CDnow", "4 7/16" },
            { "DCLK", "DoubleClick", "87 3/16" }, { "EBAY", "eBay", "180 7/8" },
            { "EWBX", "EarthWeb", "18 1/4" }, { "MKTW", "MarketWatch", "29" },
            { "TGLO", "Theglobe.com", "4 15/16" }, { "YHOO", "Yahoo!", "151 1/8" } };
    Object columns[] = { "Symbol", "Name", "Price" };
    JTable table = new JTable(rows, columns);
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);/*w  w w  . j  a v  a 2  s .c o  m*/
    f.setVisible(true);
}

From source file:GridLayoutTest.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("GridLayout Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 2));
    frame.add(new JButton("Button 1"));
    frame.add(new JButton("Button 2"));
    frame.add(new JButton("Button 3"));
    frame.add(new JButton("Button 4"));
    frame.add(new JButton("Button 5"));
    frame.add(new JButton("Button 6"));
    frame.add(new JButton("Button 7"));
    frame.add(new JButton("Button 8"));
    frame.pack();/*from  w w  w.  ja v  a2s .  c  om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    int horizontalGap = 20;
    int verticalGap = 10;
    Container contentPane = frame.getContentPane();
    FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap);
    contentPane.setLayout(flowLayout);//from   w  w  w  .  ja v a 2 s  . c o  m
    frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    for (int i = 1; i <= 5; i++) {
        contentPane.add(new JButton("Button  " + i));
    }
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.PAGE_AXIS);
    container.setLayout(layout);//from w ww  .j  a  v a  2 s  .  c  o m

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}