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:com.jaxzin.iraf.demo.CdfInv.java

public static void main(String[] args) {
    final JFreeChart chart = ChartFactory.createLineChart("Inverse CDF", "", "", createData(400),
            PlotOrientation.VERTICAL, true, true, true);

    // Customize the chart
    customizeChart(chart);/*  www  . j  a v a  2s. c o  m*/

    final JPanel panel = new ChartPanel(chart, true);
    final JFrame frame = new JFrame("Demo");
    frame.getContentPane().add(panel);
    setupJFrame(frame);
}

From source file:ElementSample.java

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

    final JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    JButton button = new JButton("Show Elements");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Document document = textArea.getDocument();
            ElementIterator iterator = new ElementIterator(document);
            Element element = iterator.first();
            while (element != null) {
                System.out.println(element.getStartOffset());
                element = iterator.next();
            }/*from  www.  j a v a  2 s.co m*/
        }
    };
    button.addActionListener(actionListener);

    content.add(scrollPane, BorderLayout.CENTER);
    content.add(button, BorderLayout.SOUTH);

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

From source file:ClippedDragImage.java

public static void main(String[] args) {
    String imageFile = "A.jpg";
    Image image = Toolkit.getDefaultToolkit().getImage(ClippedDragImage.class.getResource(imageFile));
    image = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_DEFAULT);
    JFrame frame = new JFrame("ClippedDragImage");
    frame.getContentPane().add(new ClippedDragImage(image));
    frame.setSize(300, 300);//from   w w  w .j  a  v  a2s  .  co m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(mainPanel);
    f.pack();/*from w  ww  . j a va2  s. co  m*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(final String[] av) {
    JFrame frame = new JFrame();
    Container cp = frame.getContentPane();
    cp.add(new FileTree(new File(".")));
    frame.pack();//from  w w  w.j a  va  2 s.  c o m
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:ListenerSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Offset Example");
    Container content = frame.getContentPane();
    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);
    final Document document = textArea.getDocument();
    document.addDocumentListener(new MyListener());

    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(250, 150);//w w  w  .  j  a  va  2 s.c  o  m
    frame.setVisible(true);
}

From source file:PassiveTextField1.java

public static void main(String[] args) {
    JFrame f = new JFrame("Passive Text Field");
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    final JTextField ptf = new JTextField(32);
    JTextField tf = new JTextField(32);
    JPanel p = new JPanel();
    JButton b = new JButton("OK");
    p.add(b);// w  w  w.j  a v  a 2 s  .  com
    f.getContentPane().add(ptf);
    f.getContentPane().add(tf);
    f.getContentPane().add(p);

    Keymap map = ptf.getKeymap(); // Gets the shared map
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    map.removeKeyStrokeBinding(key);

    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Action event from a text field");
        }
    };
    ptf.addActionListener(l);
    tf.addActionListener(l);

    // Make the button the default button
    f.getRootPane().setDefaultButton(b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Content of text field: <" + ptf.getText() + ">");
        }
    });
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    MaskFormatter formatter = new MaskFormatter("###-##-####");
    JFormattedTextField tf = new JFormattedTextField(formatter);
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(tf, BorderLayout.NORTH);
    JButton clickBtn = new JButton("Click me!");
    clickBtn.addActionListener(e -> {
        if (!tf.getText().matches(formatter.getMask())) {
            System.err.println("Your Input does not match the pattern!");
        } else {/*from   w w w. j a v a 2s.  c o  m*/
            System.out.println(tf.getText());
        }
    });
    panel.add(clickBtn, BorderLayout.SOUTH);
    JFrame f = new JFrame();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(panel, BorderLayout.CENTER);
    f.setSize(800, 600);
    f.setVisible(true);
}

From source file:ColorDrag.java

public static void main(String args[]) {
    // Create two JLabel objects
    final JLabel label1 = new JLabel("Drag here");
    JLabel label2 = new JLabel("Drop here");

    // Register TransferHandler objects on them: label1 transfers its
    // foreground color and label2 transfers its background color.
    label1.setTransferHandler(new TransferHandler("foreground"));
    label2.setTransferHandler(new TransferHandler("background"));

    // Give label1 a foreground color other than the default
    // Make label2 opaque so it displays its background color
    label1.setForeground(new Color(100, 100, 200));
    label2.setOpaque(true);//from w w  w  .j  ava2  s .com

    // Now look for drag gestures over label1. When one occurs,
    // tell the TransferHandler to begin a drag.
    // Exercise: modify this gesture recognition so that the drag doesn't
    // begin until the mouse has moved 4 pixels. This helps to keep
    // drags distinct from sloppy clicks. To do this, you'll need both
    // a MouseListener and a MouseMotionListener.
    label1.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            TransferHandler handler = label1.getTransferHandler();
            handler.exportAsDrag(label1, e, TransferHandler.COPY);
        }
    });

    // Create a window, add the labels, and make it all visible.
    JFrame f = new JFrame("ColorDrag");
    f.getContentPane().setLayout(new FlowLayout());
    f.getContentPane().add(label1);
    f.getContentPane().add(label2);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");

    jb.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            System.out.println("ItemEvent!");
        }/*  ww  w .jav a2s  .  c  om*/
    });

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);
    f.pack();
    f.setVisible(true);
}