Example usage for javax.swing JFrame getContentPane

List of usage examples for javax.swing JFrame getContentPane

Introduction

In this page you can find the example usage for javax.swing JFrame getContentPane.

Prototype

public Container getContentPane() 

Source Link

Document

Returns the contentPane object for this frame.

Usage

From source file:Main.java

public static void main(String s[]) {
    JFrame frame1 = new JFrame("2D Images ");
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame1.getContentPane().add("Center", new Main());
    frame1.pack();/* w  w w  .ja v a  2s . co  m*/
    frame1.setSize(new Dimension(300, 300));
    frame1.setVisible(true);
}

From source file:Main.java

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

    // Add a close button
    JButton closeButton = new JButton("Close");
    contentPane.add(closeButton);/*from  w w  w . jav a  2 s  .co  m*/

    // set the size of the frame 300 x 200
    frame.setBounds(50, 50, 300, 200);
    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);//from  w  w w  . ja va 2s.c o  m
    JScrollPane scrollPane = new JScrollPane(editor);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new Main().makeUI());
    frame.setSize(320, 240);//  w ww  .  ja  v a 2s.  c  o m
    frame.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);//  ww  w .jav a2s.c  om

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

public static void main(String arg[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", new DisplayPanel());
    frame.pack();//w ww .  j ava 2 s.  co  m
    frame.setSize(new Dimension(350, 400));
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel panel = (JPanel) frame.getContentPane();
    panel.setLayout(null);/*from   w  w  w  .  j  a v  a  2s  .  c  o m*/

    JLabel label = new JLabel("aaa");
    panel.add(label);
    Dimension size = label.getPreferredSize();
    label.setBounds(100, 100, size.width, size.height);

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

}

From source file:ToggleButtonSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JToggleButton Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    content.add(new JToggleButton("North"), BorderLayout.NORTH);
    content.add(new JToggleButton("East"), BorderLayout.EAST);
    content.add(new JToggleButton("West"), BorderLayout.WEST);
    content.add(new JToggleButton("Center"), BorderLayout.CENTER);
    content.add(new JToggleButton("South"), BorderLayout.SOUTH);
    f.setSize(300, 200);/*from   ww  w  .  j ava 2  s .co m*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new Main());
    frame.pack();/*from   w w w . j a v a2 s .  c o  m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    // Add a close button
    JButton closeButton = new JButton("Close");
    contentPane.add(closeButton);/*from  w  w w.  j a v a  2  s .  c om*/

    closeButton.addActionListener(e -> System.exit(0));

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