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

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.getContentPane().add(new TryCardLayout());
    aWindow.setVisible(true);// w w w . j ava 2s. c om
}

From source file:Main.java

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

    GroupLayout groupLayout = new GroupLayout(contentPane);

    contentPane.setLayout(groupLayout);/*from  ww w  .j av a2s.c  o  m*/

    JLabel label = new JLabel("Label");
    JButton b2 = new JButton("Second Button");

    groupLayout.setHorizontalGroup(
            groupLayout.createSequentialGroup().addComponent(label).addGap(5, 10, 50).addComponent(b2));

    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(label).addComponent(b2));

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

From source file:KeyTest.java

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

    KeyListener listener = new KeyListener() {
        public void keyPressed(KeyEvent e) {
            dumpInfo("Pressed", e);
        }/*  www  . j  ava  2s.c o m*/

        public void keyReleased(KeyEvent e) {
            dumpInfo("Released", e);
        }

        public void keyTyped(KeyEvent e) {
            dumpInfo("Typed", e);
        }

        private void dumpInfo(String s, KeyEvent e) {
            System.out.println(s);
            int code = e.getKeyCode();
            System.out.println("\tCode: " + KeyEvent.getKeyText(code));
            System.out.println("\tChar: " + e.getKeyChar());
            int mods = e.getModifiersEx();
            System.out.println("\tMods: " + KeyEvent.getModifiersExText(mods));
            System.out.println("\tLocation: " + location(e.getKeyLocation()));
            System.out.println("\tAction? " + e.isActionKey());
        }

        private String location(int location) {
            switch (location) {
            case KeyEvent.KEY_LOCATION_LEFT:
                return "Left";
            case KeyEvent.KEY_LOCATION_RIGHT:
                return "Right";
            case KeyEvent.KEY_LOCATION_NUMPAD:
                return "NumPad";
            case KeyEvent.KEY_LOCATION_STANDARD:
                return "Standard";
            case KeyEvent.KEY_LOCATION_UNKNOWN:
            default:
                return "Unknown";
            }
        }
    };

    JTextField text = new JTextField();
    text.addKeyListener(listener);
    contentPane.add(text, BorderLayout.NORTH);
    frame.pack();
    frame.show();
}

From source file:Main.java

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

    JButton closeButton = new JButton("Close");
    contentPane.add(closeButton);//from   w ww .j a  v  a2s  .  c om

    closeButton.addActionListener(e -> System.exit(0));
    // Add a MouseListener to the JButton
    closeButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseEntered(MouseEvent e) {
            closeButton.setText("Mouse has  entered!");
        }

        @Override
        public void mouseExited(MouseEvent e) {
            closeButton.setText("Mouse has  exited!");
        }
    });
    frame.pack();
    frame.setVisible(true);
}

From source file:ClipDemo.java

public static void main(String args[]) {
    JFrame mainFrame = new JFrame();
    mainFrame.getContentPane().add(new ClipDemo());
    mainFrame.pack();//ww w .  ja  v  a 2 s.  c o  m

    mainFrame.setVisible(true);
}

From source file:StyledSample.java

public static void main(String args[]) {
    String BOLD_ITALIC = "BoldItalic";
    String GRAY_PLAIN = "Gray";
    JFrame frame = new JFrame("Simple Attributes");
    Container content = frame.getContentPane();

    StyledDocument document = new DefaultStyledDocument();

    Style style = (Style) document.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setBold(style, true);
    StyleConstants.setItalic(style, true);
    document.addStyle(BOLD_ITALIC, null);

    //    style = document.getStyle(StyleContext.DEFAULT_STYLE);
    //    StyleConstants.setBold(style, false);
    //    StyleConstants.setItalic(style, false);
    //    StyleConstants.setForeground(style, Color.lightGray);
    //    document.addStyle(GRAY_PLAIN, null);

    style = document.getStyle(BOLD_ITALIC);

    // Insert content
    try {/* w  ww  . j av a 2  s.c  o m*/
        document.insertString(document.getLength(), "Hello Java\n", style);
    } catch (BadLocationException badLocationException) {
        System.err.println("Oops");
    }

    style = document.getStyle(GRAY_PLAIN);

    // Insert content
    try {
        document.insertString(document.getLength(), " - Good-bye Visual Basic\n", style);
    } 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);
}

From source file:SpringSample.java

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

    SpringLayout layout = new SpringLayout();
    contentPane.setLayout(layout);//from   w ww  . ja  v a 2  s .co m

    Component left = new JLabel("Left");
    Component right = new JTextField(15);

    contentPane.add(left);
    contentPane.add(right);
    layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane);
    layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left);

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

From source file:Main.java

public static void main(String[] args) {

    JFrame frame = new JFrame("JFrame");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    JButton counterButton = new JButton("Clicked #0");
    JButton closeButton = new JButton("Close");
    frame.setLayout(new FlowLayout());
    contentPane.add(closeButton);//from w ww.j  a  v a  2  s .  c om
    contentPane.add(counterButton);

    counterButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            counterButton.setText("Clicked #" + counter++);
        }
    });

    closeButton.addActionListener(e -> System.exit(0));

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

From source file:de.codesourcery.planning.DateAxisTestTool.java

public static void main(String[] args) {

    axis.setStartDate(DateUtils.round(new Date(), Calendar.DAY_OF_MONTH));
    axis.setRange(Duration.weeks(1));
    axis.setTickDuration(Duration.oneDay());

    JFrame frame = new JFrame();
    frame.getContentPane().add(new DateCanvas());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);//  www.j a va 2 s.  c  om
    frame.pack();
    frame.setVisible(true);
}

From source file:NumberViewer.java

public static void main(String[] args) {
    JFrame f = new JFrame("Number Viewer");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new NumberViewer());
    f.pack();//  w ww  .j a  va 2  s  .c o m
    f.setVisible(true);
}