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) {
    Object[] items = new Object[] { "Dog", "Cat", "Other" };
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel(items);
    JComboBox comboBox = new JComboBox(dcbm);
    comboBox.setPreferredSize(new Dimension(200, 20));
    comboBox.addItemListener(e -> {//w  w w  .  j ava  2 s . c o m
        Object selectedItem = comboBox.getSelectedItem();
        boolean editable = selectedItem instanceof String && ((String) selectedItem).equals("Other");
        comboBox.setEditable(editable);
    });
    comboBox.getEditor().addActionListener(e -> {
        Object newItem = comboBox.getEditor().getItem();
        DefaultComboBoxModel d = (DefaultComboBoxModel) comboBox.getModel();
        d.addElement(newItem);
        d.setSelectedItem(newItem);

    });

    JPanel content = new JPanel(new FlowLayout());
    content.add(new JLabel("Test:"));
    content.add(comboBox);

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

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage original = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    BufferedImage rotated1 = create(original, -Math.PI / 2, gc);
    BufferedImage rotated2 = create(original, +Math.PI / 4, gc);
    BufferedImage rotated3 = create(original, Math.PI, gc);

    JPanel cp = new JPanel();
    cp.add(new JLabel(new ImageIcon(original)));
    cp.add(new JLabel(new ImageIcon(rotated1)));
    cp.add(new JLabel(new ImageIcon(rotated2)));
    cp.add(new JLabel(new ImageIcon(rotated3)));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(cp);
    f.pack();//from   w  ww  .j  a v  a 2  s  .  c om
    f.setVisible(true);

}

From source file:MainClass.java

public static void main(String s[]) {
    JFrame frame = new JFrame("List Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MainClass());
    frame.pack();/*  w w  w. ja v  a2 s. c  om*/
    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.setContentPane(new Main());
    frame.setPreferredSize(new Dimension(500, 400));
    frame.pack();/*  w w  w . jav  a  2 s.  co m*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Scroll Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MainClass());
    frame.setSize(200, 200);//from   w w w.j  av  a 2  s. co m
    frame.setVisible(true);
}

From source file:SelectionMonitor.java

public static void main(String s[]) {

    JFrame frame = new JFrame("Selection Monitor");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new SelectionMonitor());
    frame.pack();//from   w  ww  . ja v  a2  s .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);

    Main demo = new Main();
    frame.setContentPane(demo.createMenuBar());

    frame.setSize(300, 100);/*from  ww  w.  ja  va2  s  .c  om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JPanel ui = new JPanel(new BorderLayout(2, 2));
    ui.setBorder(new EmptyBorder(4, 4, 4, 4));

    JPanel controls = new JPanel(new BorderLayout(2, 2));
    ui.add(controls, BorderLayout.PAGE_START);
    String s = new String(Character.toChars(8594));
    String[] items = { "Choice: right " + s + " arrow" };
    JComboBox cb = new JComboBox(items);
    controls.add(cb, BorderLayout.CENTER);
    controls.add(new JButton("Button"), BorderLayout.LINE_END);

    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40));

    ui.add(sp, BorderLayout.CENTER);

    JFrame f = new JFrame("Stretch Combo Layout");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);
    f.pack();/*from   w w  w  .  j ava 2 s . c  om*/
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:TitledExample.java

public static void main(String s[]) {
    JFrame frame = new JFrame("Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 100);//w w w. j  a va  2  s .  c  o  m
    frame.setContentPane(new TitledExample());
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String s[]) {
    JFrame frame = new JFrame("List Model Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MainClass());
    frame.setSize(260, 200);/*  w  w  w .j  av  a  2s . c  o m*/
    frame.setVisible(true);
}