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) {
    JLabel label = new JLabel("First Name");
    label.setForeground(Color.yellow);

    JFrame frame = new JFrame();
    frame.add(label);/*from w ww. j a  va  2 s.c  o m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);
}

From source file:Main.java

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

    JComponent topButton = new JButton("Left");
    JComponent bottomButton = new JButton("Right");
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    splitPane.setTopComponent(topButton);
    splitPane.setBottomComponent(bottomButton);

    horizontalFrame.add(splitPane, BorderLayout.CENTER);
    horizontalFrame.setSize(150, 150);//  ww  w .j a v  a  2  s  .com
    horizontalFrame.setVisible(true);

    splitPane.setDividerLocation(0.5);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("First Name");
    label.setForeground(Color.YELLOW);

    JFrame frame = new JFrame();
    frame.add(label);//from   w  ww .  j  a v a 2  s.  co m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("First Name");
    label.setForeground(Color.orange);

    JFrame frame = new JFrame();
    frame.add(label);/*  w ww. j  a  v  a2s .com*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("First Name");
    label.setForeground(Color.ORANGE);

    JFrame frame = new JFrame();
    frame.add(label);//w  w w .j a  v  a  2s.co m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);/*from w  ww . j  a v  a2 s  . c om*/
    frame.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));

    JPanel navigation_panel_wrap = new JPanel() {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(250, 700);
        }
    };
    JPanel content_panel_wrap = new JPanel() {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(750, 700);
        }
    };

    content_panel_wrap.setBackground(Color.green);
    navigation_panel_wrap.setBackground(Color.red);

    frame.add(navigation_panel_wrap);
    frame.add(content_panel_wrap);
    frame.pack();
    frame.setVisible(true);

}

From source file:ToolBarTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JToolBar bar;//ww w .ja  va 2 s.  c  o  m
    bar = new JToolBar();
    JToggleButton jb;
    for (int i = 0; i < 8; i++) {
        jb = new JToggleButton("" + i);
        bar.add(jb);
        if (i == 5) {
            bar.addSeparator();
        }
    }
    contentPane.add(bar, BorderLayout.NORTH);
    frame.setSize(300, 300);
    frame.show();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTree tree = new JTree();

    JFrame f = new JFrame();
    f.add(new JScrollPane(tree));
    f.setSize(300, 300);//w  w w .j a v a 2  s. c  o m
    f.setVisible(true);

    // Get paths of all selected nodes
    TreePath[] paths = tree.getSelectionPaths();

}

From source file:RelativeX.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridy = 0;/*www  . ja va2 s .c  om*/
    pane.add(new JButton("First row"), gbc);
    gbc.gridx = GridBagConstraints.RELATIVE;
    gbc.gridy = 1;
    pane.add(new JButton("Second row, first column"), gbc);
    pane.add(new JButton("Second row, second column"), gbc);
    pane.add(new JButton("Second row, third column"), gbc);
    gbc.gridy = 2;
    pane.add(new JButton("Third row"), gbc);
    f.setSize(600, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Box rowOne = Box.createHorizontalBox();
    rowOne.add(new JLabel("Username"));
    rowOne.add(new JTextField());
    Component rowTwo = Box.createHorizontalGlue();

    f.add(rowOne, BorderLayout.NORTH);
    f.add(rowTwo, BorderLayout.SOUTH);
    f.setSize(300, 200);//from   w w  w .  j a v  a 2  s . c om
    f.setVisible(true);
}