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

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

    // Set the x, y, width and height properties
    frame.setBounds(50, 50, 200, 200);/*from   w  w  w.  j  av a2 s  . c om*/

    frame.setVisible(true);
}

From source file:CreatingAWindow.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    int windowWidth = 400; // Window width in pixels
    int windowHeight = 150; // Window height in pixels
    aWindow.setBounds(50, 100, // Set position
            windowWidth, windowHeight); // and size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setVisible(true); // Display the window
}

From source file:Main.java

public static void main(String[] args) {
    // Create a frame
    JFrame frame = new JFrame("Swing");
    // Display the frame
    frame.setVisible(true);/*  www.j  av  a2  s. c o m*/
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Hello World");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(100, 100));
    frame.setVisible(true);/*from   w w  w .  j  ava  2s  .  c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Hello!!");
    frame.setAlwaysOnTop(true);/*w  ww.j  av a 2 s  .  co  m*/
    frame.setLocationByPlatform(true);
    frame.add(new JLabel("  Always visible"));
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("TitleLessJFrame");
    frame.getContentPane().add(new JLabel(" HEY!!!"));
    frame.setUndecorated(true);/*www.  j  av a2  s .c o m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame("The Frame");
    f.setSize(300, 300);/*w w w .  j  a v a 2s .c om*/
    f.setLocation(100, 100);

    JWindow w = new JWindow();
    w.setSize(300, 300);
    w.setLocation(500, 100);

    f.setVisible(true);
    w.setVisible(true);
}

From source file:SimplestFrame.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    aWindow.setBounds(50, 100, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setVisible(true);/*w  w w. j ava2 s. com*/
}

From source file:HTMLButton.java

public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
            + "<font color=\"#FF0080\"><u>Multi-line</u></font>";
    JButton button4 = new JButton(htmlButton);
    frame.add(button4);//from w  ww. j  a  v a  2  s . c om
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(300, 200);/*w ww  . j a v a  2 s .co m*/
    f.setVisible(true);

    FontMetrics metrics = f.getFontMetrics(f.getFont());

    int widthX = metrics.charsWidth(new char[] { 'a', 'b' }, 1, 2);

    System.out.println(widthX);

}