Example usage for javax.swing JFrame setContentPane

List of usage examples for javax.swing JFrame setContentPane

Introduction

In this page you can find the example usage for javax.swing JFrame setContentPane.

Prototype

@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.")
public void setContentPane(Container contentPane) 

Source Link

Document

Sets the contentPane property.

Usage

From source file:Main.java

public static void main(String[] args) {
    int ROWS = 100;
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(new JLabel("Thanks for helping out. Use tab to move around."));
    for (int i = 0; i < ROWS; i++) {
        JTextField field = new JTextField("" + i);
        field.setName("field#" + i);
        content.add(field);/*  www .j a  v  a2s . c  o  m*/
    }
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner",
            new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (!(evt.getNewValue() instanceof JComponent)) {
                        return;
                    }
                    JViewport viewport = (JViewport) content.getParent();
                    JComponent focused = (JComponent) evt.getNewValue();
                    if (content.isAncestorOf(focused)) {
                        Rectangle rect = focused.getBounds();
                        Rectangle r2 = viewport.getVisibleRect();
                        content.scrollRectToVisible(
                                new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight()));
                    }
                }
            });
    JFrame window = new JFrame();
    window.setContentPane(new JScrollPane(content));
    window.setSize(200, 200);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    try {/*from w w w .  j  a va  2s . c  om*/
        bg = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    } catch (Exception ex) {
        System.out.println(ex);
    }

    JPanel tabPanel = new JPanel(new GridBagLayout()) {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(bg, 0, 0, getWidth(), getHeight(), this);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(400, 300);
        }
    };
    JPanel buttons = new JPanel(new GridLayout(4, 1, 15, 15));
    buttons.setOpaque(false);
    for (int i = 0; i < 4; i++) {
        buttons.add(new JButton("Button"));
    }
    tabPanel.add(buttons);

    JTabbedPane tabPane = new JTabbedPane();
    tabPane.add("Panel with Bachground", tabPanel);

    JFrame frame = new JFrame();
    frame.setContentPane(tabPane);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.pack();/* w  w  w  .j a v a 2 s.com*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JButton close = new JButton("Close me programmatically");
    final JFrame f = new JFrame("Close Me");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(close);
    close.addActionListener(e -> {/*  ww  w .  j a  v a 2s. co m*/
        f.dispose();
    });
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String s[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new Main());
    frame.pack();/*from w  ww .  j a va  2 s .com*/
    frame.setVisible(true);
}

From source file:StringRectPaintPanel.java

public static void main(String[] args) {

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

    frame.setContentPane(new StringRectPaintPanel());
    frame.setSize(500, 300);/*from  ww  w  .j av a  2 s  .c  o m*/
    frame.setVisible(true);
}

From source file:SwingSuspendResume.java

public static void main(String[] args) {
    SwingSuspendResume vsr = new SwingSuspendResume();
    Thread t = new Thread(vsr);
    t.start();/*from w ww. ja  v a 2  s. c o m*/

    JFrame f = new JFrame();
    f.setContentPane(vsr);
    f.setSize(320, 200);
    f.setVisible(true);
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new MyContentPane());
    frame.pack();// ww w. ja  v a2s . c  om
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String argv[]) {
    Main pane = new Main();
    for (int n = 1; n <= 4; n += 1) {
        pane.appendNaive(Color.black, String.valueOf(n) + ' ');
    }/* w  w  w  . j a va2  s.  c om*/
    JFrame f = new JFrame("ColorPane example");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(new JScrollPane(pane));
    f.setSize(600, 400);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new PopupMenu());
    frame.validate();//from  w w  w  .  j a va  2  s. co  m
    frame.pack();
    frame.setVisible(true);
}