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

public static void main(String[] args) {
    try {//from  w  w w .j  a  v  a 2  s .c om
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new JFrame("Text Field View");
    JTextField tf = new JTextField(32);
    tf.setText("That's one small step for man...");
    f.getContentPane().add(tf);
    f.pack();
    f.setVisible(true);

    ViewDisplayer.displayViews(tf, System.out);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    int horizontalGap = 20;
    int verticalGap = 10;
    Container contentPane = frame.getContentPane();
    FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap);
    contentPane.setLayout(flowLayout);//from   w  w w. j a va2 s.  c o m
    frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    for (int i = 1; i <= 5; i++) {
        contentPane.add(new JButton("Button  " + i));
    }
    frame.pack();
    frame.setVisible(true);
}

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.add(new MouseMotionAdapterDemo());
    aWindow.setVisible(true);/*from www.  j  a  v  a 2  s .c  o m*/
}

From source file:HitTestSample.java

public static void main(String[] args) {

    JFrame f = new JFrame("HitTestSample");
    HitTestSample demo = new HitTestSample();
    f.getContentPane().add(demo, "Center");

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from   w  ww .  j  a v  a2 s . c  o m
        }
    });

    f.setSize(new Dimension(400, 250));
    f.setVisible(true);
}

From source file:TextAcceleratorExample.java

public static void main(String[] args) {
    try {/*from   www. j a v a 2s  .co  m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JLabel l;
    JTextField t;
    JButton b;
    JFrame f = new JFrame("Text Accelerator Example");
    Container cp = f.getContentPane();
    cp.setLayout(new GridBagLayout());
    cp.setBackground(UIManager.getColor("control"));
    GridBagConstraints c = new GridBagConstraints();

    c.gridx = 0;
    c.gridy = GridBagConstraints.RELATIVE;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.insets = new Insets(2, 2, 2, 2);
    c.anchor = GridBagConstraints.EAST;

    cp.add(l = new JLabel("Name:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('n');
    cp.add(l = new JLabel("House/Street:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('h');
    cp.add(l = new JLabel("City:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('c');
    cp.add(l = new JLabel("State/County:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('s');
    cp.add(l = new JLabel("Zip/Post code:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('z');
    cp.add(l = new JLabel("Telephone:", SwingConstants.RIGHT), c);
    l.setDisplayedMnemonic('t');
    cp.add(b = new JButton("Clear"), c);
    b.setMnemonic('l');

    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;

    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('n');
    c.gridx = 1;
    c.gridy = GridBagConstraints.RELATIVE;
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('h');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('c');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('s');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('z');
    cp.add(t = new JTextField(35), c);
    t.setFocusAccelerator('t');
    c.weightx = 0.0;
    c.fill = GridBagConstraints.NONE;
    cp.add(b = new JButton("OK"), c);
    b.setMnemonic('o');

    f.pack();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setVisible(true);
}

From source file:ScrollableLabel.java

public static void main(String[] args) {
    JFrame f = new JFrame("JScrollPane Demo");

    ImageIcon ii = new ImageIcon("largeJava2sLogo.gif");
    JScrollPane jsp = new JScrollPane(new ScrollableLabel(ii));
    f.getContentPane().add(jsp);
    f.setSize(300, 250);/*from   w  ww.  j a va  2  s  . co m*/
    f.setVisible(true);

}

From source file:com.moss.appprocs.swing.ProgressMonitorBean.java

public static void main(String[] args) {
    JFrame window = new JFrame("ProcessTest");
    window.getContentPane().add(new ProgressMonitorBean(new TestProcess()));
    window.setSize(400, 100);/*from   w  w w. java 2  s .  c  o  m*/
    window.setVisible(true);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:ColorSink.java

/** This is a simple test program for ColorSource and ColorSink */
public static void main(String[] args) {
    // Create a window
    JFrame f = new JFrame("ColorSourceTest");
    f.getContentPane().setLayout(new BorderLayout());

    // Add some ColorSources
    JPanel panel = new JPanel();
    f.getContentPane().add(panel, BorderLayout.NORTH);
    panel.add(new ColorSource(Color.yellow));
    panel.add(new ColorSource(Color.pink));
    panel.add(new ColorSource(Color.white));
    panel.add(new ColorSource(Color.gray));

    // Add a ColorSink
    ColorSink sink = new ColorSink();
    f.getContentPane().add(sink, BorderLayout.CENTER);

    // Pop it all up
    f.setSize(400, 300);/*from w  w w  . j a  va 2  s.c  om*/
    f.show();
}

From source file:graphs.Graphs.java

public static void main(String[] args) {
    Graphs graph = new Graphs();
    Graph<String, Integer> graph1 = new SparseGraph<String, Integer>();
    graph1.addEdge(1, "A", "C");
    graph1.addEdge(6, "A", "F");
    graph1.addEdge(5, "B", "C");
    graph1.addEdge(10, "B", "Z");
    graph1.addEdge(3, "B", "D");
    graph1.addEdge(4, "D", "E");
    System.out.println("Original: vertices and edges");
    System.out.println(graph1);//w  ww  .j  a va  2s .  c o m

    String path = BreadthSearch(graph1);
    System.out.println("print breadth first search path");
    System.out.println(path);

    Layout<String, Integer> layout = new CircleLayout<String, Integer>(graph1);
    BasicVisualizationServer<String, Integer> vv = new BasicVisualizationServer<String, Integer>(layout);

    vv.setPreferredSize(new Dimension(600, 600)); //Sets the viewing area size

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());

    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);

}

From source file:ProgressBarStep.java

public static void main(String args[]) {
    // Initialize
    final JProgressBar aJProgressBar = new JProgressBar(0, 50);
    aJProgressBar.setStringPainted(true);

    final JButton aJButton = new JButton("Start");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            aJButton.setEnabled(false);//from   w  ww. ja v  a 2 s . co  m
            Thread stepper = new BarThread(aJProgressBar);
            stepper.start();
        }
    };

    aJButton.addActionListener(actionListener);

    String title = (args.length == 0 ? "Stepping Progress" : args[0]);
    JFrame theFrame = new JFrame(title);
    theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = theFrame.getContentPane();
    contentPane.add(aJProgressBar, BorderLayout.NORTH);
    contentPane.add(aJButton, BorderLayout.SOUTH);
    theFrame.setSize(300, 200);
    theFrame.setVisible(true);
}