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();
    JTextArea textarea = new JTextArea();
    textarea.setDragEnabled(true);//from w w  w. ja v  a2s .com

    textarea.setText("Drag target");

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

    JTextField textarea1 = new JTextField();
    textarea1.setText("Drop target");
    frame.getContentPane().add(BorderLayout.SOUTH, textarea1);

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

From source file:AddingIconsToOptionPopups.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    Icon greenIcon = new ImageIcon("yourFile.gif");
    Icon redIcon = new ImageIcon("");
    Object iconArray[] = { greenIcon, redIcon };

    JOptionPane.showOptionDialog(frame, "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, iconArray, iconArray[1]);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JList list = new JList(new String[] { "one", "two", "three", "four" });
    list.setSelectionModel(new DefaultListSelectionModel() {
        public void setSelectionInterval(int index0, int index1) {
            if (index0 == index1) {
                if (isSelectedIndex(index0)) {
                    removeSelectionInterval(index0, index0);
                    return;
                }/* w w  w.  j  av a  2  s.c o  m*/
            }
            super.setSelectionInterval(index0, index1);
        }

        @Override
        public void addSelectionInterval(int index0, int index1) {
            if (index0 == index1) {
                if (isSelectedIndex(index0)) {
                    removeSelectionInterval(index0, index0);
                    return;
                }
                super.addSelectionInterval(index0, index1);
            }
        }

    });
    f.getContentPane().add(list);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    JOptionPane pane = new JOptionPane("Some message", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION) {
        @Override//from   w w  w .  jav  a2  s.c  om
        public void setValue(Object newValue) {
            super.setValue(newValue);
            JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit " + newValue);
        }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Some panel in the middle"), BorderLayout.CENTER);
    frame.add(pane, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Add the toolbar to a frame
    JFrame frame = new JFrame();
    JToolBar toolbar = new JToolBar();

    frame.getContentPane().add(toolbar, BorderLayout.NORTH);
    frame.pack();//from w  w w  .  java2  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);
    f.getContentPane().add(getPanel());/*from w  w w .ja  v a 2s  .co m*/
    f.pack();
    f.setVisible(true);
}

From source file:EmptyColumnHeader.java

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

    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
            { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
    Object columnNames[] = { "", "", "" };
    JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);//from   w  w  w  .ja v  a 2 s .c o m
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setVisible(true);/*  ww w  .j  a  v a2  s. c o m*/

    JButton button1 = new JButton("");
    JButton button2 = new JButton("");

    frame.getContentPane().add(button1);
    frame.getContentPane().add(button2);

    button1.addActionListener(e -> {
        System.out.println("Lambda");
    });

    button2.addActionListener(Main::doSomething);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Modal dialog with OK button
    String message = "Line1\nLine2";
    JFrame frame = new JFrame();
    JOptionPane.showMessageDialog(frame, message);
}

From source file:Main.java

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

    DefaultTableModel model = new DefaultTableModel();
    model.setColumnIdentifiers(new Object[] { "Column 1", "Column 2", "Column 3" });

    JTable table = new JTable(model);
    for (int count = 0; count < 3; count++) {
        model.insertRow(count, new Object[] { count, "name", "age" });
    }/*from  w w w. j  av  a 2s.c  om*/
    table.setRowHeight(1, 30);

    frame.add(new JScrollPane(table));
    frame.setLocationByPlatform(true);
    frame.pack();
    frame.setVisible(true);
}