Creating a JFrame - Java Swing

Java examples for Swing:JFrame

Description

Creating a JFrame

Demo Code

import java.awt.BorderLayout;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Main {
  public void main() {
    // Create the frame
    String title = "Frame Title";
    JFrame frame = new JFrame(title);

    // Create a component to add to the frame
    JComponent comp = new JTextArea();

    frame.getContentPane().add(comp, BorderLayout.CENTER);

    // Show the frame
    int width = 300;
    int height = 300;
    frame.setSize(width, height);//from   w  w w .  ja va2  s  .co m
    frame.setVisible(true);
  }
}

Related Tutorials