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

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Flow Layout");
    aWindow.setBounds(30, 30, 300, 300); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FlowLayout flow = new FlowLayout(); // Create a layout manager
    flow.setHgap(35); // Set the horizontal gap
    Container content = aWindow.getContentPane(); // Get the content pane
    content.setLayout(flow); // Set the container layout mgr
    // Now add six button components
    for (int i = 1; i <= 6; i++) {
        content.add(new JButton("Press " + i)); // Add a Button to content pane
    }/*from   www . j  av a 2s.c o m*/
    aWindow.setVisible(true); // Display the window
}

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[] filters = fileChooser.getChoosableFileFilters();

    frame.add(fileChooser, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(String[] args) {
    final JFrame parent = new JFrame("Parent Frame");
    parent.setLayout(new FlowLayout());
    parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    parent.setBounds(100, 100, 300, 200);
    parent.setVisible(true);/*from   w w  w.ja va2s.c om*/
    JDialog dialog1 = new JDialog(parent, "Dialog1 - Modeless Dialog");
    dialog1.setBounds(200, 200, 300, 200);
    dialog1.setVisible(true);

    JDialog dialog2 = new JDialog(parent, "Dialog2 - Document-Modal Dialog",
            Dialog.ModalityType.DOCUMENT_MODAL);
    dialog2.setBounds(300, 300, 300, 200);

    JDialog dialog3 = new JDialog(dialog2, "Dialog3 - Modeless Dialog");
    dialog3.setBounds(400, 400, 300, 200);
    dialog3.setVisible(true);

    dialog2.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(".");

    boolean b = fileChooser.getControlButtonsAreShown();

    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/* w w  w .  j  a  v a 2 s  .  c  o  m*/
    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(".");

    Icon icon = fileChooser.getIcon(new File("."));
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/*  ww w .  j av a2 s  .  c om*/
    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(".");

    String name = fileChooser.getName(new File("."));
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();/*www.  ja v a  2  s.  c  om*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel dogLabel = new JLabel("www.java2s.com");
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(dogLabel);
    //    scrollPane.getViewport().setView(dogLabel);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);/* ww w  .ja v  a  2  s.c o m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    try {/*  w ww  .j av  a  2s.  co m*/
        JEditorPane editorPane = new JEditorPane("http://www.java2s.com");
        editorPane.setEditable(false);
        String b = editorPane.getText();

        JScrollPane scrollPane = new JScrollPane(editorPane);
        frame.add(scrollPane);
    } catch (IOException e) {
        System.err.println("Unable to load: " + e);
    }

    frame.setSize(640, 480);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JComboBox<String> my = new JComboBox<>(new String[] { "HELLO WORLD", "java2s.com" });
    JFrame frame = new JFrame("");
    frame.add(my);//from  w w w .j  a  va  2s  .c om
    frame.pack();
    frame.setVisible(true);
    my.setSelectedIndex(1);
}

From source file:MediaPlayer.java

public static void main(String[] args) throws Exception {
    final JFrame frame = new JFrame("MediaPlayer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    URL url = new URL(args[0]);
    final Player player = Manager.createPlayer(url);

    player.addControllerListener(new ControllerListener() {
        public void controllerUpdate(ControllerEvent ce) {
            if (ce instanceof RealizeCompleteEvent) {
                Component visual = player.getVisualComponent();
                Component control = player.getControlPanelComponent();
                if (visual != null)
                    frame.getContentPane().add(visual, "Center");
                frame.getContentPane().add(control, "South");
                frame.pack();//from  ww  w.  ja  va  2s . com
                frame.setVisible(true);
                player.start();
            }
        }
    });

    player.realize();
}