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

public static void main(String[] args) {
    Main mainPanel = new Main();

    JFrame frame = new JFrame("CalcEg");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(mainPanel.getMainComponent());
    frame.pack();/*from w w w. ja v  a  2  s.c o  m*/
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(mainPanel);
    frame.pack();/*from   w w  w . j a v a2s.co m*/
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:TableSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JTable Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    Object rows[][] = { { "AMZN", "Amazon", "67 9/16" }, { "AOL", "America Online", "68 3/4" },
            { "BOUT", "About.com", "56 3/8" }, { "CDNW", "CDnow", "4 7/16" },
            { "DCLK", "DoubleClick", "87 3/16" }, { "EBAY", "eBay", "180 7/8" },
            { "EWBX", "EarthWeb", "18 1/4" }, { "MKTW", "MarketWatch", "29" },
            { "TGLO", "Theglobe.com", "4 15/16" }, { "YHOO", "Yahoo!", "151 1/8" } };
    Object columns[] = { "Symbol", "Name", "Price" };
    JTable table = new JTable(rows, columns);
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);/*from   w w w  . j  a va2s.  c om*/
    f.setVisible(true);
}

From source file:QuadCurve.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    QuadCurve curve = new QuadCurve();
    curve.init();/*from ww  w  .  j  a va2  s. c  o m*/
    f.getContentPane().add(curve);
    f.setDefaultCloseOperation(1);
    f.setSize(650, 250);
    f.setVisible(true);
}

From source file:EditorPaneSample.java

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

    JEditorPane editorPane = new JEditorPane("http://www.apress.com");
    editorPane.setEditable(false);//from   w w w. j  av a 2 s .c  o m

    HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(frame, editorPane);
    editorPane.addHyperlinkListener(hyperlinkListener);

    JScrollPane scrollPane = new JScrollPane(editorPane);
    content.add(scrollPane);

    frame.setSize(640, 480);
    frame.setVisible(true);
}

From source file:Main.java

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

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());

    for (int i = 1; i <= 5; i++) {
        contentPane.add(new JButton("Button  " + i));
    }//ww  w  .  j a va 2s .  c o m

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

From source file:ResizeTable.java

public static void main(String args[]) {

    Object rowData[][] = { { "1", "one", "ichi - \u4E00", "un", "I" },
            { "2", "two", "ni - \u4E8C", "deux", "II" }, { "3", "three", "san - \u4E09", "trois", "III" },
            { "4", "four", "shi - \u56DB", "quatre", "IV" }, { "5", "five", "go - \u4E94", "cinq", "V" },
            { "6", "six", "roku - \u516D", "treiza", "VI" }, { "7", "seven", "shichi - \u4E03", "sept", "VII" },
            { "8", "eight", "hachi - \u516B", "huit", "VIII" }, { "9", "nine", "kyu - \u4E5D", "neur", "IX" },
            { "10", "ten", "ju - \u5341", "dix", "X" } };

    String columnNames[] = { "#", "English", "Japanese", "French", "Roman" };

    final JTable table = new JTable(rowData, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);

    String modes[] = { "Resize All Columns", "Resize Last Column", "Resize Next Column", "Resize Off",
            "Resize Subsequent Columns" };
    final int modeKey[] = { JTable.AUTO_RESIZE_ALL_COLUMNS, JTable.AUTO_RESIZE_LAST_COLUMN,
            JTable.AUTO_RESIZE_NEXT_COLUMN, JTable.AUTO_RESIZE_OFF, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS };
    JComboBox resizeModeComboBox = new JComboBox(modes);
    int defaultMode = 4;
    table.setAutoResizeMode(modeKey[defaultMode]);
    resizeModeComboBox.setSelectedIndex(defaultMode);
    ItemListener itemListener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            JComboBox source = (JComboBox) e.getSource();
            int index = source.getSelectedIndex();
            table.setAutoResizeMode(modeKey[index]);
        }/*from w  ww  . j  a va 2s .c om*/
    };
    resizeModeComboBox.addItemListener(itemListener);

    JFrame frame = new JFrame("Resizing Table");
    Container contentPane = frame.getContentPane();

    contentPane.add(resizeModeComboBox, BorderLayout.NORTH);
    contentPane.add(scrollPane, BorderLayout.CENTER);

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

From source file:TableDemoApplet.java

public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(3);
            createGUI(frame.getContentPane());
            frame.pack();//from  w  w  w.  j a  v a 2 s  .  co m
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

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

    ComponentListener comp = new ComponentListener() {
        public void componentHidden(ComponentEvent e) {
            dump("Hidden", e);
        }/*from  w  w  w.j  a v a 2s .  c  o  m*/

        public void componentMoved(ComponentEvent e) {
            dump("Moved", e);
        }

        public void componentResized(ComponentEvent e) {
            dump("Resized", e);
        }

        public void componentShown(ComponentEvent e) {
            dump("Shown", e);
        }

        private void dump(String type, ComponentEvent e) {
            System.out.println(e.getComponent().getName() + " : " + type);
        }
    };

    JButton left = new JButton("Left");
    left.setName("Left");
    left.addComponentListener(comp);

    final JButton right = new JButton("Right");
    right.setName("Right");
    right.addComponentListener(comp);

    ActionListener action = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            right.setVisible(!right.isVisible());
        }
    };
    left.addActionListener(action);

    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, left, right);

    contentPane.add(pane, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.show();
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Command: " + e.getActionCommand());
            int modifiers = e.getModifiers();
            System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK));
            System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK));
            System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK));
            System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK));
            Object source = e.getSource();
            if (source instanceof JComboBox) {
                JComboBox jb = (JComboBox) source;
                System.out.println("Combo: " + jb.getSelectedItem());
            }//from   w w w  .  j  a  v a 2  s .  c  om
        }

        private boolean checkMod(int modifiers, int mask) {
            return ((modifiers & mask) == mask);
        }
    };

    String flavors[] = { "Item 1", "Item 2", "Item 3" };
    JComboBox jc = new JComboBox(flavors);
    jc.setMaximumRowCount(4);
    jc.setEditable(true);
    jc.addActionListener(listener);
    contentPane.add(jc, BorderLayout.NORTH);

    JButton b = new JButton("Button!");
    b.addActionListener(listener);
    contentPane.add(b, BorderLayout.CENTER);

    JPanel panel = new JPanel();
    JLabel label = new JLabel("Label 1: ");
    JTextField text = new JTextField("Type your text", 15);
    text.addActionListener(listener);
    label.setDisplayedMnemonic(KeyEvent.VK_1);
    label.setLabelFor(text);
    panel.add(label);
    panel.add(text);
    contentPane.add(panel, BorderLayout.SOUTH);

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