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.GSDemo.java

public static void main(String[] args) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Timeseries", "", "", createData(), false, true,
            true);/*from   w w w . j  a v a  2 s.  c o  m*/

    // Customize the chart
    customizeChart(chart);

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

From source file:AlignLabels.java

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

    mainFrame.setSize(500, 500);/*from w w  w .  j  av a 2  s .  c  om*/

    mainFrame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JLabel userLabel = new JLabel("User Name");
    JLabel passLabel = new JLabel("Password");
    JTextField userText = new JTextField(20);
    JPasswordField passText = new JPasswordField(20);
    JButton loginButton = new JButton("Login");

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.insets = new Insets(4, 4, 4, 4);
    gbc.gridx = 0;//from   w  ww.j  ava2 s . c  om
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(userLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(userText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(passLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(passText, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridwidth = 2;
    panel.add(loginButton, gbc);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(panel));
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    FieldComponent golfgame = new FieldComponent();
    ((Component) golfgame).setFocusable(true);
    frame.getContentPane().add(golfgame);
    frame.pack();//from ww  w . j av a 2s.co m
    frame.setVisible(true);
}

From source file:TextAreaExample.java

public static void main(String[] args) {
    JFrame f = new JFrame("Text Area Examples");
    JPanel upperPanel = new JPanel();
    JPanel lowerPanel = new JPanel();
    f.getContentPane().add(upperPanel, "North");
    f.getContentPane().add(lowerPanel, "South");

    upperPanel.add(new JTextArea(content));
    upperPanel.add(new JTextArea(content, 6, 10));
    upperPanel.add(new JTextArea(content, 3, 8));

    lowerPanel.add(new JScrollPane(new JTextArea(content, 6, 8)));
    JTextArea ta = new JTextArea(content, 6, 8);
    ta.setLineWrap(true);/* www.ja v  a  2  s  .com*/
    lowerPanel.add(new JScrollPane(ta));

    ta = new JTextArea(content, 6, 8);
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    lowerPanel.add(new JScrollPane(ta));

    f.pack();
    f.setVisible(true);
}

From source file:ImageLabelExample.java

public static void main(String[] args) {
    JLabel[] labels = new JLabel[9];

    labels[0] = makeLabel(JLabel.TOP, JLabel.LEFT);
    labels[1] = makeLabel(JLabel.TOP, JLabel.CENTER);
    labels[2] = makeLabel(JLabel.TOP, JLabel.RIGHT);
    labels[3] = makeLabel(JLabel.CENTER, JLabel.LEFT);
    labels[4] = makeLabel(JLabel.CENTER, JLabel.CENTER);
    labels[5] = makeLabel(JLabel.CENTER, JLabel.RIGHT);
    labels[6] = makeLabel(JLabel.BOTTOM, JLabel.LEFT);
    labels[7] = makeLabel(JLabel.BOTTOM, JLabel.CENTER);
    labels[8] = makeLabel(JLabel.BOTTOM, JLabel.RIGHT);

    labels[0].setEnabled(false);//  ww  w .ja  va2s  .c  om

    labels[1].setDisabledIcon(new ImageIcon("2.gif"));
    labels[1].setEnabled(false);

    labels[2].setIconTextGap(15);
    labels[3].setIconTextGap(0);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = frame.getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
    for (int i = 0; i < 9; i++)
        c.add(labels[i]);
    frame.setSize(350, 150);
    frame.setVisible(true);
}

From source file:com.google.code.facebook.graph.sna.applet.SimpleGraphDraw.java

public static void main(String[] args) throws IOException {
    JFrame jf = new JFrame();
    Graph g = getGraph();/*from  w  w w  .j ava2 s  .  co m*/
    VisualizationViewer vv = new VisualizationViewer(new FRLayout(g));
    jf.getContentPane().add(vv);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.pack();
    jf.setVisible(true);
}

From source file:Main.java

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

    JPanel buttonPanel = new JPanel();
    JButton nextButton = new JButton("Next");
    buttonPanel.add(nextButton);/*from   w  w w. j  av a 2s  .  c  om*/
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    final JPanel cardPanel = new JPanel();
    final CardLayout cardLayout = new CardLayout();
    cardPanel.setLayout(cardLayout);

    for (int i = 1; i <= 5; i++) {
        JButton card = new JButton("Card " + i);
        card.setPreferredSize(new Dimension(200, 200));
        String cardName = "card" + 1;
        cardPanel.add(card, cardName);
    }
    contentPane.add(cardPanel, BorderLayout.CENTER);
    nextButton.addActionListener(e -> cardLayout.next(cardPanel));

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws BadLocationException {
    JFrame jf = new JFrame("StyledText");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = jf.getContentPane();

    JTextPane pane = new JTextPane();
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setBold(set, true);

    // Set the attributes before adding text
    pane.setCharacterAttributes(set, true);
    pane.setText("java2s.com ");

    set = new SimpleAttributeSet();
    StyleConstants.setItalic(set, true);
    StyleConstants.setForeground(set, Color.red);
    StyleConstants.setBackground(set, Color.blue);

    Document doc = pane.getStyledDocument();
    doc.insertString(doc.getLength(), "Swing ", set);

    set = new SimpleAttributeSet();
    StyleConstants.setFontSize(set, 24);

    doc.insertString(doc.getLength(), "Tutorial", set);

    JScrollPane scrollPane = new JScrollPane(pane);
    cp.add(scrollPane, BorderLayout.CENTER);

    jf.setSize(400, 300);/*ww w .  ja va2s .co m*/
    jf.setVisible(true);
}

From source file:TextPaneSample.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "TextPane Example" : args[0]);
    JFrame frame = new JFrame(title);
    Container content = frame.getContentPane();

    StyleContext context = new StyleContext();
    StyledDocument document = new DefaultStyledDocument(context);

    Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT);
    StyleConstants.setFontSize(style, 14);
    StyleConstants.setSpaceAbove(style, 4);
    StyleConstants.setSpaceBelow(style, 4);

    // Insert content
    try {//from w w w.j  ava  2 s  .  c o  m
        document.insertString(document.getLength(), message, style);
    } catch (BadLocationException badLocationException) {
        System.err.println("Oops");
    }

    SimpleAttributeSet attributes = new SimpleAttributeSet();
    StyleConstants.setBold(attributes, true);
    StyleConstants.setItalic(attributes, true);

    // Insert content
    try {
        document.insertString(document.getLength(), "Hello Java", attributes);
    } catch (BadLocationException badLocationException) {
        System.err.println("Oops");
    }

    // Third style for icon/component
    Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE);

    Icon icon = new ImageIcon("Computer.gif");
    JLabel label = new JLabel(icon);
    StyleConstants.setComponent(labelStyle, label);

    // Insert content
    try {
        document.insertString(document.getLength(), "Ignored", labelStyle);
    } catch (BadLocationException badLocationException) {
        System.err.println("Oops");
    }

    JTextPane textPane = new JTextPane(document);
    textPane.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textPane);
    content.add(scrollPane, BorderLayout.CENTER);

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