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

public static void main(String[] args) {
    JFrame f = new JFrame("Vertical BoxLayout-managed container");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    for (float align = 0.0f; align <= 1.0f; align += 0.25f) {
        JButton button = new JButton("X Alignment = " + align);
        button.setAlignmentX(align);/*from w  w  w  . jav  a 2s. c o  m*/
        pane.add(button);
    }
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:CreatingSerifItalicBoldFont.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Pick to Change Background");

    Font myFont = new Font("Serif", Font.ITALIC | Font.BOLD, 12);

    button.setFont(myFont);//ww  w .java 2s.c  om

    f.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:ToggleButtonSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JToggleButton Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    content.add(new JToggleButton("North"), BorderLayout.NORTH);
    content.add(new JToggleButton("East"), BorderLayout.EAST);
    content.add(new JToggleButton("West"), BorderLayout.WEST);
    content.add(new JToggleButton("Center"), BorderLayout.CENTER);
    content.add(new JToggleButton("South"), BorderLayout.SOUTH);
    f.setSize(300, 200);/* ww w  . j  a v  a 2s. c o  m*/
    f.setVisible(true);
}

From source file:ABevelBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Bevel Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border raisedBorder = BorderFactory.createRaisedBevelBorder();

    JButton button = new JButton("Raised");
    button.setBorder(raisedBorder);//w  ww.java2s  .  co  m
    frame.add(button);

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

From source file:Main.java

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

    JFileChooser fileChooser = new JFileChooser(".");

    FileView fileView = fileChooser.getFileView();
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();// w w  w. j  av  a2 s . c  o m
    frame.setVisible(true);
}

From source file:Main.java

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

    JTextArea areaFiftyOne = new JTextArea();
    JTextArea areaFiftyTwo = new JTextArea();
    areaFiftyTwo.setDocument(areaFiftyOne.getDocument());
    JTextArea areaFiftyThree = new JTextArea();
    areaFiftyThree.setDocument(areaFiftyOne.getDocument());

    frame.setLayout(new GridLayout(3, 1));
    frame.add(new JScrollPane(areaFiftyOne));
    frame.add(new JScrollPane(areaFiftyTwo));
    frame.add(new JScrollPane(areaFiftyThree));

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 300);/*from w w  w  .j a v a  2s  . c  o  m*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame x = new JFrame("Look at me");
    x.setSize(200, 300);//from w ww .  jav  a2 s.  c o  m
    x.setVisible(true);
    x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FileOutputStream f;
    try {
        f = new FileOutputStream("Test.xml");
        XMLEncoder e = new XMLEncoder(new BufferedOutputStream(f));
        e.writeObject(x);
        e.close();
    } catch (Exception e) {
    }
}

From source file:Main.java

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

    JFileChooser fileChooser = new JFileChooser(".");

    FileFilter f = fileChooser.getFileFilter();
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/*  w  w  w.j a  va2s.  c  o  m*/
    frame.setVisible(true);
}

From source file:FlowLayoutChangingGap.java

public static void main(String[] args) {

    JFrame aWindow = new JFrame("This is a Flow Layout");
    aWindow.setBounds(50, 50, 500, 500);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FlowLayout flow = new FlowLayout(FlowLayout.LEFT, 20, 30);
    Container content = aWindow.getContentPane(); // Get the content pane
    content.setLayout(flow); // Set the container layout mgr
    for (int i = 1; i <= 6; i++) {
        content.add(new JButton("Press " + i)); // Add a Button to content pane
    }//  w  w w .java2 s . c o m
    aWindow.setVisible(true); // Display the window
}

From source file:MainClass.java

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

    AncestorListener ancestorListener = new AncestorListener() {
        public void ancestorAdded(AncestorEvent ancestorEvent) {
            System.out.println("Added");
        }//from   ww  w . j  a  v a2 s. co m

        public void ancestorMoved(AncestorEvent ancestorEvent) {
            System.out.println("Moved");
        }

        public void ancestorRemoved(AncestorEvent ancestorEvent) {
            System.out.println("Removed");
        }
    };
    frame.getRootPane().addAncestorListener(ancestorListener);
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.getRootPane().setVisible(false);
    frame.getRootPane().setVisible(true);
}