List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. From source file:InternalFrameEventTest.java
public static void main(String[] a) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JLayeredPane desktop = new JDesktopPane(); desktop.setOpaque(false);//from w ww .j a v a2 s. co m contentPane.add(desktop, BorderLayout.CENTER); desktop.add(createLayer("One"), JLayeredPane.POPUP_LAYER); desktop.add(createLayer("Two"), JLayeredPane.DEFAULT_LAYER); desktop.add(createLayer("Three"), JLayeredPane.PALETTE_LAYER); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
static public void main(String args[]) throws Exception { JFrame frame = new JFrame("ShowImageIR.java"); Panel panel = new Main(args[0]); frame.getContentPane().add(panel); frame.setSize(400, 400);//w w w . j a v a2s . c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JComboBox c = new JComboBox(); c.addPopupMenuListener(new PopupMenuListener() { @Override/*from ww w . j a va 2s . c o m*/ public void popupMenuCanceled(PopupMenuEvent e) { System.out.println(e.getSource()); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { System.out.println(e.getSource()); } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { System.out.println(e.getSource()); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().setLayout(new FlowLayout()); f.getContentPane().add(c); f.pack(); f.setVisible(true); }
From source file:GridBagLayoutRemainder.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); pane.add(new JButton("First row, first column"), gbc); pane.add(new JButton("First row, second column"), gbc); pane.add(new JButton("First row, third column"), gbc); gbc.gridx = 0;/*from ww w.j a va 2 s .c o m*/ pane.add(new JButton("Second row"), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; pane.add(new JButton("Third row, gridwidth set to REMAINDER"), gbc); f.setSize(600, 300); f.setVisible(true); }
From source file:ContainerTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); ContainerListener cont = new ContainerListener() { ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Selected: " + e.getActionCommand()); }//from w w w .j a v a 2 s. co m }; public void componentAdded(ContainerEvent e) { Component c = e.getChild(); if (c instanceof JButton) { JButton b = (JButton) c; b.addActionListener(listener); } } public void componentRemoved(ContainerEvent e) { Component c = e.getChild(); if (c instanceof JButton) { JButton b = (JButton) c; b.removeActionListener(listener); } } }; contentPane.addContainerListener(cont); contentPane.setLayout(new GridLayout(3, 2)); contentPane.add(new JButton("First")); contentPane.add(new JButton("Second")); contentPane.add(new JButton("Third")); contentPane.add(new JButton("Fourth")); contentPane.add(new JButton("Fifth")); frame.setSize(300, 200); frame.show(); }
From source file:MainClass.java
public static void main(String argv[]) { JFrame f = new JFrame("FactoryDemo"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(demo1(), BorderLayout.NORTH); f.getContentPane().add(new JTextField(), BorderLayout.SOUTH); f.setSize(240, 160);/*from ww w . j av a2 s . co m*/ f.setVisible(true); }
From source file:FancyButton.java
public static void main(String[] args) { FancyButton b1 = new FancyButton(new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif")); FancyButton b2 = new FancyButton(new ImageIcon("4.gif"), new ImageIcon("1.gif"), new ImageIcon("2.gif")); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(b1);// w w w .j a v a 2s . com c.add(b2); f.pack(); f.setVisible(true); }
From source file:EditabilityExample.java
public static void main(String[] args) { try {//from ww w. j a va 2 s.co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Editability Example"); f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS)); f.getContentPane().add(firstField); JTextField tf = new JTextField("A read-only text field", 20); tf.setEditable(false); f.getContentPane().add(tf); JTextArea ta = new JTextArea("An editable\ntext area", 2, 20); ta.setBorder(BorderFactory.createLoweredBevelBorder()); f.getContentPane().add(ta); ta = new JTextArea("A read-only\ntext area", 2, 20); ta.setBorder(BorderFactory.createLoweredBevelBorder()); ta.setEditable(false); f.getContentPane().add(ta); f.pack(); f.show(); if (args.length == 1 && args[0].equals("disable")) { // Toggle the enabled state of the first // text field every 10 seconds Timer t = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent evt) { firstField.setEnabled(!firstField.isEnabled()); firstField.setText(firstFieldText + (firstField.isEnabled() ? "" : " (disabled)")); } }); t.start(); } }
From source file:RelativeX.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 0;//from w ww. j a v a 2s. co m pane.add(new JButton("First row"), gbc); gbc.gridx = GridBagConstraints.RELATIVE; gbc.gridy = 1; pane.add(new JButton("Second row, first column"), gbc); pane.add(new JButton("Second row, second column"), gbc); pane.add(new JButton("Second row, third column"), gbc); gbc.gridy = 2; pane.add(new JButton("Third row"), gbc); f.setSize(600, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); Icon normalIcon = new TriangleIcon(Color.red, TriangleIcon.State.NORMAL); Icon pressedIcon = new TriangleIcon(Color.red, TriangleIcon.State.PRESSED); Icon rolloverIcon = new TriangleIcon(Color.red, TriangleIcon.State.ROLLOVER); JButton b = new JButton("Button", normalIcon); b.setPressedIcon(pressedIcon);// w w w . java 2 s . c o m b.setRolloverIcon(rolloverIcon); b.setRolloverEnabled(true); contentPane.add(b, BorderLayout.NORTH); frame.setSize(300, 100); frame.show(); }