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

public static void main(String args[]) {
    JFrame frame = new JFrame("Use TextAction");
    Container contentPane = frame.getContentPane();
    Dimension empty = new Dimension(0, 0);

    final JTextArea leftArea = new JTextArea();
    JScrollPane leftScrollPane = new JScrollPane(leftArea);
    leftScrollPane.setPreferredSize(empty);

    final JTextArea rightArea = new JTextArea();
    JScrollPane rightScrollPane = new JScrollPane(rightArea);
    rightScrollPane.setPreferredSize(empty);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);/*from w  ww. j  a  v a  2 s. co m*/
    JMenu menu = new JMenu("Options");
    menuBar.add(menu);
    JMenuItem menuItem;

    Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction);
    menuItem = menu.add(readAction);
    menuItem.setText("Make read-only");
    Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction);
    menuItem = menu.add(writeAction);
    menuItem.setText("Make writable");

    menu.addSeparator();

    Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction);
    menuItem = menu.add(cutAction);
    menuItem.setText("Cut");
    Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction);
    menuItem = menu.add(copyAction);
    menuItem.setText("Copy");
    Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction);
    menuItem = menu.add(pasteAction);
    menuItem.setText("Paste");

    contentPane.add(splitPane, BorderLayout.CENTER);
    frame.setSize(400, 250);
    frame.setVisible(true);
    splitPane.setDividerLocation(.5);
}

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().getMainPanel());
    frame.pack();/* w w w.j  a  va 2s .co  m*/
    frame.setVisible(true);
}

From source file:HtmlToolTipDemo.java

public static void main(String[] a) {
    JFrame mainFrame = new JFrame();

    JLabel label = new JLabel("label");

    label.setToolTipText("<html>First line<br>Second Line</html>");
    mainFrame.getContentPane().add(label);

    mainFrame.setSize(100, 100);/*w  ww. ja va2 s .co  m*/

    mainFrame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Boolean.TRUE);
    DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(Boolean.FALSE);
    DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(Boolean.FALSE);
    root.add(child1);/*from w  w w .  ja  va 2 s.c o  m*/
    root.add(child2);
    DefaultTreeModel model = new DefaultTreeModel(root);

    JTree tree = new JTree(model);
    tree.setCellRenderer(new TreeRenderer());

    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath pathForLocation = tree.getPathForLocation(e.getX(), e.getY());
            Object lastPathComponent = pathForLocation.getLastPathComponent();
            if (lastPathComponent instanceof DefaultMutableTreeNode) {
                Boolean oldObject = (Boolean) ((DefaultMutableTreeNode) lastPathComponent).getUserObject();
                ((DefaultMutableTreeNode) lastPathComponent).setUserObject(!oldObject);
                model.nodeChanged((DefaultMutableTreeNode) lastPathComponent);
            }
        }
    });

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(tree, BorderLayout.CENTER);
    frame.setSize(800, 600);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    JSpinner jspinner = makeDigitsOnlySpinnerUsingDocumentFilter();
    frame.getContentPane().add(jspinner, BorderLayout.CENTER);
    frame.getContentPane().add(new JButton("just another widget"), BorderLayout.SOUTH);
    frame.pack();//from w  w  w.  ja  v a2 s  . c  o m
    frame.setVisible(true);
}

From source file:JListBackground.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Brute Force Algorithm");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    addComponentsToPane(frame.getContentPane());
    frame.pack();/*from  w w w. ja v  a  2  s  . c o  m*/
    frame.setSize(800, 600);
    frame.setVisible(true);
}

From source file:MainClass.java

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

    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);/*from  w w  w. jav  a 2  s. c  o m*/

    Component left = new JLabel("Name");
    Component right = new JTextField(15);

    contentPane.add(left);
    contentPane.add(right);

    layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame f = new JFrame();
    f.setBackground(new Color(0, true)); // 1.7.0
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(makeUI());
    f.setSize(320, 240);//  ww w  . j a v  a2  s.c  o m
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(800, 600);//from   w  w  w  .jav a 2 s  . c  om
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setBackground(Color.RED);
    frame.getContentPane().add(new Main());
    frame.setVisible(true);
}

From source file:AlignmentSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(0, 1));
    JTextField textField = new JTextField("Left");
    textField.setHorizontalAlignment(JTextField.LEFT);
    content.add(textField);/*from   w  w  w .  j ava 2 s  .com*/
    textField = new JTextField("Center");
    textField.setHorizontalAlignment(JTextField.CENTER);
    content.add(textField);
    textField = new JTextField("Right");
    textField.setHorizontalAlignment(JTextField.RIGHT);
    content.add(textField);
    textField = new JTextField("Leading");
    textField.setHorizontalAlignment(JTextField.LEADING);
    content.add(textField);
    textField = new JTextField("Trailing");
    textField.setHorizontalAlignment(JTextField.TRAILING);
    content.add(textField);
    frame.pack();
    frame.setSize(250, (int) frame.getSize().getHeight());
    frame.setVisible(true);
}