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() throws HeadlessException 

Source Link

Document

Constructs a new frame that is initially invisible.

Usage

From source file:Main.java

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

    checkBox.setToolTipText("Italic font");

    frame.add(checkBox, BorderLayout.NORTH);
    frame.setSize(300, 100);/*from w ww.  j  ava 2 s.c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String... args) {
    JFrame f = new JFrame();
    JButton button;/*from  ww w.j a  v  a 2  s  .c  om*/

    JPanel p = new JPanel();
    button = new JButton("Button");
    p.setLayout(null);
    button.setBounds(40, 100, 100, 60);
    p.add(button);

    f.add(p);
    // setLayout(null);
    f.setDefaultCloseOperation(3);
    f.setSize(400, 400);
    f.setVisible(true);
}

From source file:Main.java

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

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    int width = (int) screenSize.getWidth();
    int height = (int) screenSize.getHeight();
    Dimension newDim = new Dimension(width, height - 40);

    frame.setSize(newDim);//  ww w.  j  a  va 2  s . co m

    frame.setVisible(true); // FIRST visible = true
    frame.setResizable(false); // THEN resizable = false
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable t = new JTable(10, 1);
    frame.add(new JScrollPane(t));

    t.getSelectionModel().clearSelection();
    t.getSelectionModel().addSelectionInterval(5, 6);
    t.getSelectionModel().addSelectionInterval(8, 8);
    frame.pack();/*from www. ja  v  a2 s.  c  om*/
    frame.setVisible(true);
}

From source file:Main.java

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

    JTextPane ta = new JTextPane();
    ta.setContentType("text/html");
    ta.setText("<HTML><BODY><CODE> import java.io.*; <br> public class MyIO{}</CODE><br></BODY></HTML>");
    JScrollPane jsp = new JScrollPane(ta);
    f.getContentPane().add(jsp);/*from w w  w .ja  v a2 s  . c  om*/

    f.setSize(300, 200);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

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

    JTable table = new JTable(4, 5); // 4 rows & 5 columns

    table.setRowSelectionAllowed(false);
    table.setColumnSelectionAllowed(false);
    table.setCellSelectionEnabled(false);

    frame.add(new JScrollPane(table));

    frame.setSize(300, 200);/*w w  w  . j  a v  a 2s.c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String argv[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String testStr = "Paste text here.";
    JTextArea wrapArea = new JTextArea(testStr, 20, 40);
    wrapArea.setLineWrap(true);//from   w w  w  . j a  va  2 s  . co  m
    wrapArea.setWrapStyleWord(true);
    wrapArea.setCaretPosition(testStr.length());
    frame.add(new JScrollPane(wrapArea));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setResizable(false);// w w w. j a  v a 2  s .  c  o  m
    JTextArea textArea = new JTextArea(25, 30);

    JScrollPane textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    window.add(textScroll);
    window.pack();
    window.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(null);/*w  w  w.j  av  a2  s.  c o  m*/

    JButton b1 = new JButton("Button");
    JButton b2 = new JButton("2");
    contentPane.add(b1);
    contentPane.add(b2);

    b1.setBounds(10, 10, 100, 20);
    b2.setBounds(120, 10, 150, 40);

    frame.setBounds(0, 0, 350, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JTextArea ta = new JTextArea(5, 32);
    ta.setText("That's one small step for man...\nOne giant leap for mankind.");
    ta.setLineWrap(true);//w w w .  j av a  2s . c o  m
    ta.setWrapStyleWord(true);

    f.getContentPane().add(ta);
    f.setSize(100, 100);
    f.setVisible(true);

}