Example usage for javax.swing JFrame setContentPane

List of usage examples for javax.swing JFrame setContentPane

Introduction

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

Prototype

@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.")
public void setContentPane(Container contentPane) 

Source Link

Document

Sets the contentPane property.

Usage

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//  w  w  w.java  2 s  .co  m
        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            Panel panel = new Panel();
            frame.setContentPane(panel);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

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

    frame.setSize(250, 250);//from   w w w.j ava2s  .c om
    frame.setLocation(200, 200);
    frame.setContentPane(new Main());
    frame.setVisible(true);
}

From source file:GridBag2.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GridBag2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(225, 150);/*w  ww .  j a v  a 2  s  .  c  o  m*/
    frame.setLocation(200, 200);
    frame.setContentPane(new GridBag2());
    frame.setVisible(true);
}

From source file:GridBag4.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GridBag4");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300, 100);//from  www.  j  av  a 2 s .c o m
    frame.setLocation(200, 200);
    frame.setContentPane(new GridBag4());
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame frame = new JFrame("MainClass");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(225, 150);//from   ww w.  ja v  a2  s .  com
    frame.setLocation(200, 200);
    frame.setContentPane(new MainClass());
    frame.setVisible(true);
}

From source file:IteratorTest.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(new IteratorTest());
    f.pack();//  w  w w .  j  a  va  2  s .  c om
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JProgressBar progressBar = new JProgressBar(0, 10);

    final CounterTask task = new CounterTask();
    task.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if ("progress".equals(evt.getPropertyName())) {
                progressBar.setValue((Integer) evt.getNewValue());
            }//from   w w w.  j a  v a 2 s.c  om
        }
    });
    JButton startButton = new JButton("Start");
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            task.execute();
        }
    });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            task.cancel(true);
        }
    });

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(startButton);
    buttonPanel.add(cancelButton);

    JPanel cp = new JPanel();
    LayoutManager layout = new BoxLayout(cp, BoxLayout.Y_AXIS);
    cp.setLayout(layout);
    cp.add(buttonPanel);
    cp.add(progressBar);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(4, 4));
    ui.setBorder(new EmptyBorder(6, 6, 6, 6));

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEADING));
    ui.add(controls, BorderLayout.PAGE_START);
    int s = 100;//  ww w  .ja v  a 2 s  .c om
    Dimension[] sizes = { new Dimension(s * 4, s * 2), new Dimension(s * 6, s * 3),
            new Dimension(s * 8, s * 4) };
    final JComboBox cb = new JComboBox(sizes);
    controls.add(cb);
    final JPanel[] panels = new JPanel[sizes.length];
    for (int ii = 0; ii < sizes.length; ii++) {
        Dimension d = sizes[ii];
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
        JPanel p = new JPanel(new GridLayout());
        JLabel l = new JLabel(new ImageIcon(bi));
        p.add(l);
        panels[ii] = p;
    }
    ItemListener sizeListener = new ItemListener() {

        JPanel current = panels[0];

        @Override
        public void itemStateChanged(ItemEvent e) {
            JPanel next = panels[cb.getSelectedIndex()];
            swapComponentsAndResizeUI(ui, current, next);
            current = next;
        }
    };
    cb.addItemListener(sizeListener);

    ui.add(panels[0], BorderLayout.CENTER);

    JFrame f = new JFrame("Three Sized Panels");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:GridBag3.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GridBag3");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);/*www .  j  a v  a  2 s  .  com*/
    frame.setLocation(200, 200);
    frame.setContentPane(new GridBag3());
    frame.setVisible(true);
}

From source file:QandE.ComponentDisplayer.java

public static void main(String[] args) {
    JFrame f = new JFrame("ComponentDisplayer");

    JPanel p = new JPanel(new BorderLayout());
    p.add(new XMarksTheSpot(), BorderLayout.CENTER);

    f.setContentPane(p);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();/*from   ww  w.  j av  a 2s  . c om*/
    f.setVisible(true);
}