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) {
    final JFrame frame = new JFrame();
    frame.setMinimumSize(new Dimension(200, 200));
    frame.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent evt) {
            Dimension size = frame.getSize();
            Dimension min = frame.getMinimumSize();
            if (size.getWidth() < min.getWidth()) {
                frame.setSize((int) min.getWidth(), (int) size.getHeight());
            }/*from   w ww . j ava 2s.  c o  m*/
            if (size.getHeight() < min.getHeight()) {
                frame.setSize((int) size.getWidth(), (int) min.getHeight());
            }
        }
    });
    frame.setSize(300, 300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    JScrollPane listScrollPane = new JScrollPane();
    String[] stringArray = { "Testing", "This", "Stuff" };
    JList<String> rowList = new JList<>(stringArray);

    rowList.setVisibleRowCount(2);//www  .j  a va  2  s .c  o  m
    listScrollPane.setViewportView(rowList);
    panel.setLayout(new BorderLayout());
    panel.add(listScrollPane);
    frame.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

}

From source file:LoadingWebPageToJEditorPane.java

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

    JEditorPane editorPane = new JEditorPane();

    editorPane.setPage(new URL("http://www.java2s.com"));

    frame.add(new JScrollPane(editorPane));

    frame.setSize(300, 200);/*from   ww  w .j av  a 2  s .  c  o m*/
    frame.setVisible(true);
}

From source file:GettingSettingSelectedItem.java

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

    String[] mystring = { "Java", "JBuilder", "JFC", "Swing" };
    final JList jList1 = new JList(mystring);
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object contents = jList1.getSelectedValue();
            System.out.println(contents);
        }// w ww .j  a v a 2s .c  om
    });

    frame.add(jList1, "Center");
    frame.add(jButton1, "South");

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel panel = new JPanel();
    Container c = frame.getContentPane();
    panel.setSize(100, 100);//from   w  w w.java 2 s .c o m
    panel.setLayout(new GridLayout(1000, 1));
    for (int i = 0; i < 1000; i++)
        panel.add(new JLabel("JLabel " + i));

    JScrollPane jsp = new JScrollPane(panel);
    c.add(jsp);
    frame.setSize(100, 100);
    frame.setVisible(true);

}

From source file:BasicDraw.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.add(new MyComponent());
    frame.setSize(300, 300);/*  w  ww. ja  v  a2  s . c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);/*from  ww w  .  jav a2s .  c o m*/
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    gbc.fill = GridBagConstraints.NONE;

    gbl.setConstraints(component, gbc);
    frame.add(component);

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);/* w w w .ja  va 2 s  .  c o m*/
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.weightx = 1;
    gbc.weighty = 2;
    gbl.setConstraints(component, gbc);

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);/*w w  w.j a  va 2 s  .c  o m*/
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    gbc.fill = GridBagConstraints.VERTICAL;

    gbl.setConstraints(component, gbc);
    frame.add(component);

    frame.pack();
    frame.setVisible(true);
}

From source file:TextArea.java

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

    JTextArea area = new JTextArea();
    area.setLineWrap(true);//from   www .  java 2s  .c om
    area.setWrapStyleWord(true);
    area.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    f.add(new JScrollPane(area));
    f.setSize(new Dimension(350, 300));

    f.setLocationRelativeTo(null);
    f.setVisible(true);
}