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) {
    JRadioButton dem = new JRadioButton("Bill", false);
    dem.setActionCommand("Bill");
    JRadioButton rep = new JRadioButton("Bob", false);
    rep.setActionCommand("Bob");
    JRadioButton ind = new JRadioButton("Ross", false);
    ind.setActionCommand("Ross");

    final ButtonGroup group = new ButtonGroup();
    group.add(dem);//from  w ww. j a v a2s .  c  o m
    group.add(rep);
    group.add(ind);

    class VoteActionListener implements ActionListener {
        public void actionPerformed(ActionEvent ex) {
            String choice = group.getSelection().getActionCommand();
            System.out.println("ACTION Candidate Selected: " + choice);
        }
    }

    class VoteItemListener implements ItemListener {
        public void itemStateChanged(ItemEvent ex) {
            String item = ((AbstractButton) ex.getItemSelectable()).getActionCommand();
            boolean selected = (ex.getStateChange() == ItemEvent.SELECTED);
            System.out.println("ITEM Candidate Selected: " + selected + " Selection: " + item);
        }
    }

    ActionListener al = new VoteActionListener();
    dem.addActionListener(al);
    rep.addActionListener(al);
    ind.addActionListener(al);

    ItemListener il = new VoteItemListener();
    dem.addItemListener(il);
    rep.addItemListener(il);
    ind.addItemListener(il);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = frame.getContentPane();
    c.setLayout(new GridLayout(4, 1));
    c.add(new JLabel("Please Cast Your Vote"));
    c.add(dem);
    c.add(rep);
    c.add(ind);
    frame.pack();
    frame.setVisible(true);
}

From source file:URLMonitorPanel.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame("URL Monitor");
    Container c = frame.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
    Timer t = new Timer();
    String[] u = new String[] { "http://www.java2s.com", "http://www.java2s.com" };

    for (int i = 0; i < u.length; i++) {
        c.add(new URLMonitorPanel(u[i], t));
    }/* ww  w  .ja  v a  2 s . c  o m*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    frame.pack();
    frame.show();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setPreferredSize(new Dimension(300, 280));

    Main ch = new Main();
    ch.setDate(new Date());
    frame.getContentPane().add(ch);
    frame.setUndecorated(true);/*from  w ww .  ja va 2s.co m*/

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

From source file:ButtonFocus.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Action Sample");

    JButton focusButton = new JButton("Focused");
    JButton notFocusButton = new JButton("Not Focused");

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(focusButton);//from ww w  .j  a  v a  2 s. co  m
    contentPane.add(notFocusButton);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setPreferredSize(new Dimension(300, 280));

    Main ch = new Main();
    frame.getContentPane().add(ch);
    frame.setUndecorated(true);//from   w  w  w .  j a  v a2  s  . c  o  m

    MoveMouseListener mml = new MoveMouseListener(ch);
    ch.addMouseListener(mml);
    ch.addMouseMotionListener(mml);

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

From source file:MyButtonUI.java

public static void main(String argv[]) {
    JFrame f = new JFrame();
    f.setSize(400, 300);/*from w w w .j av  a2s  .com*/
    f.getContentPane().setLayout(new FlowLayout());

    JPanel p = new JPanel();
    JButton bt1 = new JButton("Click Me");
    bt1.setUI(new MyButtonUI());
    p.add(bt1);
    f.getContentPane().add(p);
    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    f.addWindowListener(wndCloser);
    f.setVisible(true);
}

From source file:LabelTextPos.java

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

    Container content = frame.getContentPane();
    content.setLayout(new GridLayout(2, 2));

    Border border = LineBorder.createGrayLineBorder();
    Icon warnIcon = new ImageIcon("Warn.gif");

    JLabel label1 = new JLabel(warnIcon);
    label1.setText("Left-Bottom");
    label1.setHorizontalTextPosition(JLabel.LEFT);
    label1.setVerticalTextPosition(JLabel.BOTTOM);
    label1.setBorder(border);//from ww w.  java2 s  .c o  m
    content.add(label1);

    JLabel label2 = new JLabel(warnIcon);
    label2.setText("Right-TOP");
    label2.setHorizontalTextPosition(JLabel.RIGHT);
    label2.setVerticalTextPosition(JLabel.TOP);
    label2.setBorder(border);
    content.add(label2);

    JLabel label3 = new JLabel(warnIcon);
    label3.setText("Center-Center");
    label3.setHorizontalTextPosition(JLabel.CENTER);
    label3.setVerticalTextPosition(JLabel.CENTER);
    label3.setBorder(border);
    content.add(label3);

    JLabel label4 = new JLabel(warnIcon);
    label4.setText("Center-Bottom");
    label4.setHorizontalTextPosition(JLabel.CENTER);
    label4.setVerticalTextPosition(JLabel.BOTTOM);
    label4.setBorder(border);
    content.add(label4);

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

From source file:JFlap_2.EditingGraphViewer1.java

/**
 * @param args the command line arguments
 *///from   www  .ja v  a 2 s .  c om
public static void main(String[] args) {
    EditingGraphViewer1 sgv = new EditingGraphViewer1();
    // Layout<V, E>, VisualizationViewer<V,E>
    Layout<Integer, String> layout = new StaticLayout(sgv.g);
    layout.setSize(new Dimension(300, 300));
    VisualizationViewer<Integer, String> vv = new VisualizationViewer<Integer, String>(layout);
    vv.setPreferredSize(new Dimension(350, 350));
    // Show vertex and edge labels
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    EditingModalGraphMouse gm = new EditingModalGraphMouse(vv.getRenderContext(), sgv.vertexFactory,
            sgv.edgeFactory);
    vv.setGraphMouse(gm);

    JFrame frame = new JFrame("Editing Graph Viewer 1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    JMenuBar menuBar = new JMenuBar();
    JMenu modeMenu = gm.getModeMenu();
    modeMenu.setText("Mouse Mode");
    modeMenu.setIcon(null);
    modeMenu.setPreferredSize(new Dimension(80, 20));

    menuBar.add(modeMenu);
    frame.setJMenuBar(menuBar);
    gm.setMode(ModalGraphMouse.Mode.EDITING);
    frame.pack();
    frame.setVisible(true);

}

From source file:AppendingTextPane.java

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

    JFrame f = new JFrame("Text Pane with Scrolling Append");
    final AppendingTextPane atp = new AppendingTextPane();
    f.getContentPane().add(new JScrollPane(atp));
    f.setSize(200, 200);
    f.setVisible(true);

    // Add some text every second
    Timer t = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String timeString = fmt.format(new Date());
            atp.appendText(timeString + "\n");
        }

        SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss");
    });
    t.start();
}

From source file:ArcApp.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.getContentPane().add(new ArcApp());
    f.setDefaultCloseOperation(1);/*from  ww w.  ja v  a 2  s.co  m*/
    f.setSize(700, 550);
    f.setVisible(true);
}