List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. 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);// ww w . j ava 2 s .co m closeButton.addActionListener(e -> System.exit(0)); // Add a MouseListener to the JButton closeButton.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @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:ResourceModExample.java
public static void main(String[] args) { Border border = BorderFactory.createRaisedBevelBorder(); Border tripleBorder = new CompoundBorder(new CompoundBorder(border, border), border); UIManager.put("Button.border", tripleBorder); UIManager.put("InternalFrame.closeIcon", new ImageIcon("close.gif")); UIManager.put("InternalFrame.iconizeIcon", new ImageIcon("iconify.gif")); UIManager.put("InternalFrame.maximizeIcon", new ImageIcon("maximize.gif")); UIManager.put("InternalFrame.altMaximizeIcon", new ImageIcon("altMax.gif")); UIManager.put("InternalFrame.titleFont", new Font("Serif", Font.ITALIC, 12)); UIManager.put("ScrollBar.width", new Integer(30)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); JDesktopPane desk = new JDesktopPane(); c.add(desk, BorderLayout.CENTER); JButton cut = new JButton("Cut"); JButton copy = new JButton("Copy"); JButton paste = new JButton("Paste"); JPanel p = new JPanel(new FlowLayout()); p.add(cut);/*from w w w.j a v a 2 s . co m*/ p.add(copy); p.add(paste); c.add(p, BorderLayout.SOUTH); JInternalFrame inf = new JInternalFrame("MyFrame", true, true, true, true); JLabel l = new JLabel(new ImageIcon("luggage.jpeg")); JScrollPane scroll = new JScrollPane(l); inf.setContentPane(scroll); inf.setBounds(10, 10, 350, 280); desk.add(inf); inf.setVisible(true); f.setSize(380, 360); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane;//from www. j a va2 s .c om JTextField txtFoo = new JTextField(10); JPanel pnlFoo = new JPanel(); pnlFoo.add(new JButton("Button 1")); pnlFoo.add(new JLabel("Foo")); pnlFoo.add(txtFoo); JTextField txtBar = new JTextField(10); JPanel pnlBar = new JPanel(); pnlBar.add(new JButton("Button 3")); pnlBar.add(new JLabel("Bar")); pnlBar.add(txtBar); tabbedPane = new JTabbedPane(); tabbedPane.addTab("Tab 1", pnlFoo); tabbedPane.addTab("Tab 2", pnlBar); tabbedPane.addChangeListener(e -> { Component comp = tabbedPane.getSelectedComponent(); if (comp.equals(pnlFoo)) { txtFoo.requestFocusInWindow(); } else if (comp.equals(pnlBar)) { txtBar.requestFocusInWindow(); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(460, 200); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); frame.setVisible(true); txtFoo.requestFocusInWindow(); }
From source file:KeymapExample.java
public static void main(String[] args) { JTextArea area = new JTextArea(6, 32); Keymap parent = area.getKeymap(); Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent); KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); Action actionU = new UpWord(); newmap.addActionForKeyStroke(u, actionU); Action actionList[] = area.getActions(); Hashtable lookup = new Hashtable(); for (int j = 0; j < actionList.length; j += 1) lookup.put(actionList[j].getValue(Action.NAME), actionList[j]); KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction); newmap.addActionForKeyStroke(L, actionL); KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK); Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction); newmap.addActionForKeyStroke(W, actionW); area.setKeymap(newmap);//from www. ja va 2s . c o m JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("This is a test."); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new GridBagLayout()); for (int i = 0; i < 25; i++) { JTextField field = new JTextField("Field " + i, 20); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = i;// w ww.j a v a2s.c o m panel.add(field, constraints); } JScrollPane scrollPane = new JScrollPane(panel); JButton removeButton = new JButton("Remove Field"); removeButton.addActionListener(e -> { if (panel.getComponentCount() >= 1) { panel.remove(panel.getComponentCount() - 1); scrollPane.revalidate(); scrollPane.repaint(); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(640, 480); f.setLocation(200, 200); f.getContentPane().add(scrollPane); f.getContentPane().add(removeButton, BorderLayout.SOUTH); f.setVisible(true); }
From source file:JMFPlayer.java
public static void main(String[] argv) { JFrame f = new JFrame("JMF Player Demo"); Container frameCP = f.getContentPane(); JMFPlayer p = new JMFPlayer(f, argv.length == 0 ? "file:///C:/music/midi/beet5th.mid" : argv[0]); frameCP.add(BorderLayout.CENTER, p); f.setSize(200, 200);/*from w w w .j a v a 2 s . c o m*/ f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:SizingSamples.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JList jlist1 = new JList(labels); jlist1.setVisibleRowCount(4);/*from w w w. j ava 2 s . c o m*/ DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000); for (int i = 0; i < 100; i++) { for (int j = 0; j < 10; j++) { model.addElement(labels[j]); } } JScrollPane scrollPane1 = new JScrollPane(jlist1); contentPane.add(scrollPane1, BorderLayout.NORTH); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); contentPane.add(scrollPane2, BorderLayout.CENTER); JList jlist3 = new JList(labels); jlist3.setVisibleRowCount(4); contentPane.add(jlist3, BorderLayout.SOUTH); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 200);//w ww. j av a2s . c o m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.add(new Main()); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("SpringLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Set the content pane's layout to a SpringLayout SpringLayout springLayout = new SpringLayout(); contentPane.setLayout(springLayout); // Add two JButtons to the content pane JButton b1 = new JButton("Button 1"); JButton b2 = new JButton("Button Second"); // Create Constraints objects for b1 and b2 SpringLayout.Constraints b1c = new SpringLayout.Constraints(); SpringLayout.Constraints b2c = new SpringLayout.Constraints(); // Create a Spring object for y value for b1 and b2 Spring yPadding = Spring.constant(20); // Set (10, 20) for (x, y) for b1 b1c.setX(Spring.constant(10)); b1c.setY(yPadding);// www . ja va 2s . com // Set (150, 20) for (x, y) for b2 b2c.setX(Spring.constant(150)); b2c.setY(yPadding); // Use the Constraints object while adding b1 and b2 contentPane.add(b1, b1c); contentPane.add(b2, b2c); frame.pack(); frame.setVisible(true); }
From source file:House.java
public static void main(String[] a) { JFrame f = new JFrame(); f.getContentPane().add(new House()); f.setDefaultCloseOperation(1);/*from w w w .j a va 2 s .c om*/ f.setSize(700, 550); f.setVisible(true); }