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

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

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);/*w  w w.j a v  a  2 s  .c  om*/
    frame.setVisible(true);
}

From source file:CustomBorderSample.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
    JFrame frame = new JFrame("Custom Border");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    JList jlist = new JList(labels);
    ListCellRenderer renderer = new FocusedTitleListCellRenderer();
    jlist.setCellRenderer(renderer);/* w w  w  . j av  a  2s  . co m*/
    JScrollPane sp = new JScrollPane(jlist);
    contentPane.add(sp, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:DynamicIconExample.java

public static void main(String[] args) {
    final JSlider width = new JSlider(JSlider.HORIZONTAL, 1, 150, 75);
    final JSlider height = new JSlider(JSlider.VERTICAL, 1, 150, 75);

    class DynamicIcon implements Icon {
        public int getIconWidth() {
            return width.getValue();
        }/*w  w w . java 2s .  c om*/

        public int getIconHeight() {
            return height.getValue();
        }

        public void paintIcon(Component c, Graphics g, int x, int y) {
            g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
        }
    }

    Icon icon = new DynamicIcon();
    final JLabel dynamicLabel = new JLabel(icon);

    class Updater implements ChangeListener {
        public void stateChanged(ChangeEvent ev) {
            dynamicLabel.repaint();
        }
    }
    Updater updater = new Updater();

    width.addChangeListener(updater);
    height.addChangeListener(updater);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container c = f.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(width, BorderLayout.NORTH);
    c.add(height, BorderLayout.WEST);
    c.add(dynamicLabel, BorderLayout.CENTER);
    f.setSize(210, 210);
    f.setVisible(true);
}

From source file:LoadSync.java

public static void main(String args[]) {
    final String filename = "Test.html";
    JFrame frame = new JFrame("Loading/Saving Example");
    Container content = frame.getContentPane();

    final JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);// ww  w.  ja v  a 2  s.  co  m
    JScrollPane scrollPane = new JScrollPane(editorPane);
    content.add(scrollPane, BorderLayout.CENTER);

    editorPane.setEditorKit(new HTMLEditorKit());

    JPanel panel = new JPanel();

    // Setup actions
    Action loadAction = new AbstractAction() {
        {
            putValue(Action.NAME, "Load");
        }

        public void actionPerformed(ActionEvent e) {
            doLoadCommand(editorPane, filename);
        }
    };
    JButton loadButton = new JButton(loadAction);
    panel.add(loadButton);

    content.add(panel, BorderLayout.SOUTH);

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

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JButton button = new JButton("Click me");
    button.addActionListener(e -> JOptionPane.showMessageDialog(frame, "Hello World!"));
    frame.getContentPane().add(button);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();//  ww w  . j  av  a2  s.  c  o  m
    frame.setVisible(true);
}

From source file:ShowOff.java

public static void main(String[] args) {
    try {//from  w ww  .j  ava2 s  .  co  m
        String filename = "largeJava2sLogo.jpg";
        String message = "Java Source and Support";
        int split = 4;
        JFrame f = new JFrame();
        f.getContentPane().setLayout(new BorderLayout());
        ShowOff showOff = new ShowOff(filename, message, split);
        f.add(showOff, BorderLayout.CENTER);
        f.setSize(f.getPreferredSize());
        f.setResizable(false);
        f.setVisible(true);
    } catch (Exception e) {
        System.out.println(e);
        System.exit(0);
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container content = aWindow.getContentPane();
    content.setLayout(new FlowLayout(FlowLayout.LEFT));
    content.add(new JButton("www.java2s.com"));
    content.add(new JLabel("www.java2s.com"));
    content.add(new JTextField("www.java2s.com"));
    aWindow.setVisible(true);/* w  ww. ja va  2  s.com*/
}

From source file:FtfInputVerifier.java

public static void main(String argv[]) {

    java.net.URL u = null;/*from w w w.j av a2 s .com*/
    try {
        u = new java.net.URL("http://www.ora.com/");
    } catch (java.net.MalformedURLException ignored) {
    }

    // create two identical JFormattedTextFields
    JFormattedTextField ftf1 = new JFormattedTextField(u);
    JFormattedTextField ftf2 = new JFormattedTextField(u);

    // and set an InputVerifier on one of them
    ftf2.setInputVerifier(new InputVerifier() {
        public boolean verify(JComponent input) {
            if (!(input instanceof JFormattedTextField))
                return true; // give up focus
            return ((JFormattedTextField) input).isEditValid();
        }
    });

    JPanel p = new JPanel(new java.awt.GridLayout(0, 2, 3, 8));
    p.add(new JLabel("plain JFormattedTextField:", JLabel.RIGHT));
    p.add(ftf1);
    p.add(new JLabel("FTF with InputVerifier:", JLabel.RIGHT));
    p.add(ftf2);
    p.add(new JLabel("plain JTextField:", JLabel.RIGHT));
    p.add(new JTextField(u.toString()));
    p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    JFrame f = new JFrame("FtfInputVerifier");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JLabel("Try to delete the colon in each field.", JLabel.CENTER),
            java.awt.BorderLayout.NORTH);
    f.getContentPane().add(p, java.awt.BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JTextArea textarea = new JTextArea();
    textarea.setDragEnabled(true);//from w  w w  . java 2s  . c  om

    textarea.setText("Drag target");

    frame.getContentPane().add(BorderLayout.CENTER, textarea);

    JTextField textarea1 = new JTextField();
    textarea1.setText("Drop target");
    frame.getContentPane().add(BorderLayout.SOUTH, textarea1);

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

From source file:TextLayoutLeft.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setSize(300, 300);/*from w  w  w  . j  ava 2 s  .  c  om*/
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new TextLayoutLeft());
    f.setVisible(true);
}