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[] arg) {
    DefaultListModel<String> listModel = new DefaultListModel<String>();
    for (int i = 0; i < 10; i++) {
        listModel.addElement("Item " + (i + 1));
    }/*from   w  ww  . ja v a2  s .c o m*/

    JList<String> list = new JList<String>(listModel);
    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isRightMouseButton(me)) {
                list.clearSelection();
            }
        }
    });

    JScrollPane listScrollPane = new JScrollPane(list);
    JFrame f = new JFrame();
    f.getContentPane().add(listScrollPane);

    f.setSize(500, 400);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container content = frame.getContentPane();

    content.setLayout(new GridLayout(0, 2));

    JTextArea leftTextArea = new JTextArea();
    content.add(leftTextArea);/*  w w  w. j ava2s  .c  o m*/
    leftTextArea.paste();

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new BorderLayout());
    final JTree tree = new JTree();
    panel.add(new JScrollPane(tree));
    JButton btn = new JButton("Press Me");
    btn.addActionListener(et -> {// w ww.  j a va  2 s  .  c  om
        for (Enumeration e = ((TreeNode) tree.getModel().getRoot()).children(); e.hasMoreElements();) {
            TreeNode tn = (TreeNode) e.nextElement();
            tree.expandPath(new TreePath(((DefaultTreeModel) tree.getModel()).getPathToRoot(tn)));
        }
    });
    panel.add(btn, BorderLayout.SOUTH);
    JFrame frame = new JFrame("");
    frame.getContentPane().add(panel);
    frame.setSize(300, 300);
    frame.setLocation(100, 100);
    frame.pack();
    frame.show();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel(dynamicFont.getName());
    testLabel.setFont(dynamicFont32Pt);//w  w w .java2s.c  o m
    JFrame frame = new JFrame("Font Loading Demo");
    frame.getContentPane().add(testLabel);
    frame.pack();
    frame.setVisible(true);
}

From source file:ParagraphLayout.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.getContentPane().add(new ParagraphLayout());
    f.setSize(350, 250);/*from   w  w w.j ava2s  .  c o  m*/
    f.show();
}

From source file:Main.java

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

From source file:Main.java

public static void main(String[] args) throws Exception {

    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel("Dynamically loaded font \"" + dynamicFont.getName() + "\"");
    testLabel.setFont(dynamicFont32Pt);/*from w w  w .j av  a2s .c o  m*/
    JFrame frame = new JFrame("Font Loading Demo");
    frame.getContentPane().add(testLabel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    DefaultListModel<String> model = new DefaultListModel<>();
    JList<String> sList = new JList<>(model);
    for (int i = 0; i < 100; i++) {
        model.addElement("String " + i);
    }//from   www .jav a  2  s. c  om

    sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    sList.setVisibleRowCount(-1);
    sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);

    JFrame frame = new JFrame("Foo001");
    frame.getContentPane().add(new JScrollPane(sList));
    frame.getContentPane().setPreferredSize(new Dimension(400, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    JFrame jf = new JFrame("Demo");
    Container cp = jf.getContentPane();
    MyCanvas tl = new MyCanvas();
    cp.add(tl);//from   ww w .ja  v  a 2 s  .  c  om
    jf.setSize(300, 200);
    jf.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.getContentPane().add(new Main());
    f.setSize(850, 250);/*from w  w w .  ja va 2 s.  c o m*/
    f.setVisible(true);

}