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

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

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setResizeWeight(1.0);/*from w  ww .  j  av a2s. c  om*/
    splitPane.setTopComponent(new JLabel("www.java2s.com"));

    splitPane.setBottomComponent(new JLabel("www.java2s.com"));

    frame.add(splitPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

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

    Container contentPane = frame.getContentPane();
    Box hBox = Box.createHorizontalBox();
    hBox.add(new JButton("First"));
    hBox.add(new JButton("Previous"));
    hBox.add(Box.createHorizontalGlue());
    hBox.add(new JButton("Next"));
    hBox.add(new JButton("Last"));

    contentPane.add(hBox, BorderLayout.SOUTH);
    frame.pack();/*from w w  w .  j  a va2 s.c o m*/
    frame.setVisible(true);
}

From source file:FocusCycleSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Focus Cycle Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new GridLayout(3, 3));
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + i);
        frame.add(button);//from  w w  w  . j a va 2 s. c o m
    }
    JPanel panel = new JPanel();
    panel.setFocusCycleRoot(true);
    panel.setFocusTraversalPolicyProvider(true);
    panel.setLayout(new GridLayout(1, 3));
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 3));
        panel.add(button);
    }
    frame.add(panel);
    for (int i = 0; i < 3; i++) {
        JButton button = new JButton("" + (i + 6));
        frame.add(button);
    }
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("SpringLayout2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    SpringLayout springLayout = new SpringLayout();
    contentPane.setLayout(springLayout);

    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("Button Second");

    contentPane.add(b1);//from w w  w.  j a  v  a  2s  . c  om
    contentPane.add(b2);

    springLayout.putConstraint(SpringLayout.WEST, b1, 10, SpringLayout.WEST, contentPane);
    springLayout.putConstraint(SpringLayout.NORTH, b1, 20, SpringLayout.NORTH, contentPane);

    springLayout.putConstraint(SpringLayout.WEST, b2, 10, SpringLayout.EAST, b1);

    springLayout.putConstraint(SpringLayout.NORTH, b2, 20, SpringLayout.NORTH, contentPane);

    springLayout.putConstraint(SpringLayout.SOUTH, contentPane, 10, SpringLayout.SOUTH, b1);

    springLayout.putConstraint(SpringLayout.EAST, contentPane, 10, SpringLayout.EAST, b2);

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

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JEditorPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JEditorPane editor = new JEditorPane("text/html",
            "<H3>Help</H3><center><IMG src=file:///c:/a.jpg></center><li>One<li><i>Two</i><li><u>Three</u>");
    editor.setEditable(false);/*  w  w w .  jav a2 s . co  m*/
    JScrollPane scrollPane = new JScrollPane(editor);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:ABevelBorderLoweredBevelBorder.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Bevel Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border loweredBorder = BorderFactory.createLoweredBevelBorder();

    JButton button = new JButton("Raised");
    button.setBorder(loweredBorder);/* ww w  .  j  a  v  a 2  s  . co m*/
    frame.add(button);

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

From source file:AlignmentSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(0, 1));
    JTextField textField = new JTextField("Left");
    textField.setHorizontalAlignment(JTextField.LEFT);
    content.add(textField);/* ww  w  .  java2  s  .  c  o m*/
    textField = new JTextField("Center");
    textField.setHorizontalAlignment(JTextField.CENTER);
    content.add(textField);
    textField = new JTextField("Right");
    textField.setHorizontalAlignment(JTextField.RIGHT);
    content.add(textField);
    textField = new JTextField("Leading");
    textField.setHorizontalAlignment(JTextField.LEADING);
    content.add(textField);
    textField = new JTextField("Trailing");
    textField.setHorizontalAlignment(JTextField.TRAILING);
    content.add(textField);
    frame.pack();
    frame.setSize(250, (int) frame.getSize().getHeight());
    frame.setVisible(true);
}

From source file:JComboBoxTest.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("JComboBox Test");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String[] selections = { "green", "red", "orange", "dark blue" };
    JComboBox comboBox = new JComboBox(selections);
    comboBox.setSelectedIndex(1);/* w  ww  .  ja  va 2s.  c  o m*/
    System.out.println(comboBox.getSelectedItem());
    frame.add(comboBox);
    frame.pack();
    frame.setVisible(true);
}

From source file:WindowAdapterTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Window Listener");
    WindowListener listener = new WindowAdapter() {
        public void windowClosing(WindowEvent w) {
            System.exit(0);/*from  w w  w .j  av a 2s .c  o  m*/
        }
    };
    frame.addWindowListener(listener);
    frame.setSize(300, 300);
    frame.show();
}

From source file:Main.java

public static void main(String[] argv) {
    JFrame demo = new JFrame("GridBag demo, to center a component");
    JPanel parentPanel = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.CENTER;
    gridbag.setConstraints(parentPanel, constraints);
    parentPanel.setLayout(gridbag);/*from   ww w .j av  a 2 s . c o  m*/
    Label centerLabel = new Label(" AAA...");
    parentPanel.add(centerLabel);
    demo.add(parentPanel);
    demo.setSize(500, 500);
    demo.setVisible(true);
}