List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. From source file:MouseDrag.java
public static void main(String[] av) { JFrame f = new JFrame("Mouse Dragger"); Container cp = f.getContentPane(); if (av.length < 1) { System.err.println("Usage: MouseDrag imagefile"); System.exit(1);//from w ww.ja v a 2s . co m } Image im = Toolkit.getDefaultToolkit().getImage(av[0]); // create a MouseDrag object MouseDrag j = new MouseDrag(im); cp.setLayout(new BorderLayout()); cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java")); cp.add(BorderLayout.CENTER, j); cp.add(BorderLayout.SOUTH, status = new Label()); status.setSize(f.getSize().width, status.getSize().height); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:MainClass.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(200, 200, 200, 200); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = aWindow.getContentPane(); content.add(new MouseMotionEvents()); aWindow.setVisible(true);/*from ww w. j a va 2s . c o m*/ }
From source file:MainClass.java
public static void main(String s[]) { MainClass example = new MainClass(); example.pane = new JTextPane(); example.pane.setPreferredSize(new Dimension(250, 250)); example.pane.setBorder(new BevelBorder(BevelBorder.LOWERED)); JFrame frame = new JFrame("Menu Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(example.menuBar);// www .j a v a2 s . c om frame.getContentPane().add(example.pane, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Add a close button JButton closeButton = new JButton("Close"); Container contentPane = frame.getContentPane(); contentPane.add(closeButton);/*w ww . ja v a2s .co m*/ // Calculates and sets appropriate size for the frame frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setVisible(true);/*from w w w . j a v a2 s. c o m*/ JButton button1 = new JButton(""); JButton button2 = new JButton(""); frame.getContentPane().add(button1); frame.getContentPane().add(button2); button1.addActionListener(e -> { System.out.println("Lambda"); }); button2.addActionListener(Main::doSomething); }
From source file:DoubleBufferedImage.java
public static void main(String[] argv) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DoubleBufferedImage a = new DoubleBufferedImage(); frame.getContentPane().add(a); frame.setSize(300, 300);/*from w ww. ja va2s .c o m*/ a.init(); a.start(); frame.setVisible(true); }
From source file:TArea.java
public static void main(String[] a) { JFrame f = new JFrame(); TArea area = new TArea(); area.init();// w w w .j ava 2 s . c o m f.getContentPane().add(area); f.setDefaultCloseOperation(1); f.setSize(650, 450); 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.setLayout(new BorderLayout()); frame.pack();//from w w w .j a va2 s. co m Container contentPane = frame.getContentPane(); contentPane.setLayout(null); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setBounds((i * 75) + 475, 25, 75, 100); System.out.println(panel.getBounds()); contentPane.add(panel); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3)); } System.out.println(getComponentAt(contentPane, new Point(475, 25))); System.out.println(getComponentAt(contentPane, new Point(100, 25))); frame.setVisible(true); }
From source file:SelectingJListSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); contentPane.add(scrollPane1, BorderLayout.WEST); ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.print("First index: " + listSelectionEvent.getFirstIndex()); System.out.print(", Last index: " + listSelectionEvent.getLastIndex()); boolean adjust = listSelectionEvent.getValueIsAdjusting(); System.out.println(", Adjusting? " + adjust); if (!adjust) { JList list = (JList) listSelectionEvent.getSource(); int selections[] = list.getSelectedIndices(); Object selectionValues[] = list.getSelectedValues(); for (int i = 0, n = selections.length; i < n; i++) { if (i == 0) { System.out.print(" Selections: "); }/*from w ww . j ava2 s .co m*/ System.out.print(selections[i] + "/" + selectionValues[i] + " "); } System.out.println(); } } }; jlist.addListSelectionListener(listSelectionListener); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); System.out.println("Double-clicked on: " + o.toString()); } } } }; jlist.addMouseListener(mouseListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { // create a hierarchy of nodes MutableTreeNode root = new DefaultMutableTreeNode("A"); MutableTreeNode bNode = new DefaultMutableTreeNode("B"); MutableTreeNode cNode = new DefaultMutableTreeNode("C"); root.insert(bNode, 0);/* ww w .j av a2s. c om*/ root.insert(cNode, 1); bNode.insert(new DefaultMutableTreeNode("1"), 0); bNode.insert(new DefaultMutableTreeNode("2"), 1); cNode.insert(new DefaultMutableTreeNode("1"), 0); cNode.insert(new DefaultMutableTreeNode("2"), 1); final DefaultTreeModel model = new DefaultTreeModel(root); final JTree tree = new JTree(model); final JTextField nameField = new JTextField("Z"); final JButton button = new JButton("Add"); button.setEnabled(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TreePath tp = tree.getSelectionPath(); MutableTreeNode insertNode = (MutableTreeNode) tp.getLastPathComponent(); int insertIndex = 0; if (insertNode.getParent() != null) { MutableTreeNode parent = (MutableTreeNode) insertNode.getParent(); insertIndex = parent.getIndex(insertNode) + 1; insertNode = parent; } MutableTreeNode node = new DefaultMutableTreeNode(nameField.getText()); model.insertNodeInto(node, insertNode, insertIndex); } }); JPanel addPanel = new JPanel(new GridLayout(2, 1)); addPanel.add(nameField); addPanel.add(button); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath tp = e.getNewLeadSelectionPath(); button.setEnabled(tp != null); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.getContentPane().add(new JScrollPane(tree)); frame.getContentPane().add(addPanel, BorderLayout.SOUTH); frame.setVisible(true); }