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[] args) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
    DefaultTreeModel model = new DefaultTreeModel(root);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(new JTree(model)));
    f.getContentPane().add(new JButton(new AbstractAction("Add thousand children") {
        @Override/*  www  .  java  2  s  . com*/
        public void actionPerformed(ActionEvent e) {
            int offset = root.getChildCount() + 1;
            for (int i = 0; i < 1000; i++) {
                DefaultMutableTreeNode child = new DefaultMutableTreeNode("Person " + (i + offset));
                // model.insertNodeInto(child, root, root.getChildCount());
                root.add(child);
            }
            model.nodeStructureChanged(root);
        }
    }), BorderLayout.PAGE_END);
    f.pack();
    f.setVisible(true);
}

From source file:TransformScale.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.getContentPane().add(new TransformScale());
    f.setSize(650, 550);//from  ww w.  j  a  va  2  s.c  o  m
    f.show();
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    Container pane = f.getContentPane();
    Icon icon = new RedOvalIcon();
    final Action action = new MyAction("Hello", icon);
    // Add tooltip
    action.putValue(Action.SHORT_DESCRIPTION, "World");
    JToolBar jt1 = new JToolBar();
    JButton b1 = new JButton(action);
    jt1.add(b1);//from   w  ww.  j  a va 2  s .com
    pane.add(jt1, BorderLayout.NORTH);
    JToolBar jt2 = new JToolBar();
    JButton b2 = new JButton(action);
    jt2.add(b2);
    pane.add(jt2, BorderLayout.SOUTH);
    JButton jb = new JButton("Toggle Action");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            action.setEnabled(!action.isEnabled());
        }
    });
    pane.add(jb, BorderLayout.CENTER);
    f.setSize(200, 200);
    f.show();
}

From source file:TransformTransRotation.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.getContentPane().add(new TransformTransRotation());
    f.setSize(450, 350);//from w  w w .  jav a  2  s .c o m
    f.show();
}

From source file:Main.java

public static void main(String[] args) {
    JLabel label = new JLabel("Hello");
    label.setOpaque(true);/* w w w  . jav a  2s. co  m*/
    label.setBackground(Color.red);

    JPanel bottomPanel = new JPanel(new BorderLayout());
    bottomPanel.add(label, BorderLayout.LINE_END);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(bottomPanel, BorderLayout.PAGE_END);
    mainPanel.setPreferredSize(new Dimension(400, 400));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(mainPanel);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:GradientPane.java

public static void main(String[] a) {
    JFrame window = new JFrame("Acyclic Gradient Paint");
    window.setBounds(30, 30, 300, 300);/*  www  .j av  a 2 s .c om*/
    window.getContentPane().add(new GradientPane());
    window.setVisible(true);
}

From source file:TransformersRotationTranslation.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.getContentPane().add(new TransformersRotationTranslation());
    f.setSize(350, 450);/*from  w  w  w .  j ava2  s .c  o  m*/
    f.show();
}

From source file:GridBagLayoutFill.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.gridx = 0;// w  w  w  .  ja v a 2  s. c  o m
    gbc.gridy = GridBagConstraints.RELATIVE;
    pane.add(new JButton("This button's preferred width " + "is large because its text is long"), gbc);
    pane.add(new JButton("Small centered button"), gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    pane.add(new JButton("Expands to fill column width"), gbc);
    f.setSize(400, 300);
    f.setVisible(true);
}

From source file:TransformShear.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.getContentPane().add(new TransformShear());
    f.setSize(450, 350);//from  w w w  .ja  v a2s  . c  o  m
    f.show();
}

From source file:Main.java

public static void main(String[] args) {
    int ROW_HEIGHT = 40;
    String[] TABLE_COLUMNS = { "Foo", "Bar" };
    DefaultTableModel tableModel = new DefaultTableModel(TABLE_COLUMNS, 2);
    JTable table = new JTable(tableModel);
    table.setRowHeight(ROW_HEIGHT);//from  w ww  . ja  v a2 s. c  o m
    JScrollPane scrollpane = new JScrollPane(table);
    JButton addRowBtn = new JButton(new AbstractAction("Add Row") {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            tableModel.addRow(new String[] { "", "" });
        }
    });
    JPanel btnPanel = new JPanel();
    btnPanel.add(addRowBtn);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scrollpane, BorderLayout.CENTER);
    f.getContentPane().add(btnPanel, BorderLayout.PAGE_END);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}