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) { Main mainPanel = new Main(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(mainPanel); f.setJMenuBar(mainPanel.createMenuBar()); f.pack();/*from w w w . j a v a 2 s . co m*/ f.setVisible(true); }
From source file:FileTableDemo.java
public static void main(String[] args) { // Figure out what directory to display; File dir;//from www . j a v a 2s . c o m if (args.length > 0) dir = new File(args[0]); else dir = new File(System.getProperty("user.home")); // Create a TableModel object to represent the contents of the directory FileTableModel model = new FileTableModel(dir); // Create a JTable and tell it to display our model JTable table = new JTable(model); // Display it all in a scrolling window and make the window appear JFrame frame = new JFrame("FileTableDemo"); frame.getContentPane().add(new JScrollPane(table), "Center"); frame.setSize(600, 400); frame.setVisible(true); }
From source file:AreaAdding.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new AreaAdding()); frame.pack();/* www . j a v a2 s . c o m*/ frame.setSize(new Dimension(400, 300)); frame.setVisible(true); }
From source file:EditorSample.java
public static void main(String args[]) { JFrame f = new JFrame("JEditorPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JEditorPane editor = new JEditorPane("text/html", "<H3>Help</H3><center><IMG src=file:///c:/cpress/code/Ch01/logo.jpg></center><li>One<li><i>Two</i><li><u>Three</u>"); editor.setEditable(false);/*from ww w.ja v a 2 s . c om*/ JScrollPane scrollPane = new JScrollPane(editor); content.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:LabelFor.java
public static void main(String args[]) { JFrame f = new JFrame("LabelFor Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JLabel label = new JLabel("Username"); JTextField textField = new JTextField(); label.setDisplayedMnemonic(KeyEvent.VK_U); label.setLabelFor(textField);/*from w w w.jav a2 s . co m*/ Container box = Box.createHorizontalBox(); box.add(label); box.add(textField); content.add(box, BorderLayout.NORTH); content.add(new JButton("Submit"), BorderLayout.SOUTH); f.setSize(300, 200); f.setVisible(true); }
From source file:ActionTest.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()); System.out.println("Modifiers: "); 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()); }//ww w . j a v a 2 s .c o m } 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.show(); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new CheckCombo().getContent()); f.setSize(300, 160);//from w w w .j a v a 2 s . co m f.setLocation(200, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] av) { JFrame frame = new JFrame(); Container cp = frame.getContentPane(); cp.add(new Main(new File("."))); frame.pack();//from w w w. jav a 2s. co m frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:SimpleAttributeSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Simple Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); // Insert content try {//from ww w.j av a 2s .c om document.insertString(document.getLength(), "Hello Java", attributes); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.lightGray); // Insert content try { document.insertString(document.getLength(), " - Good-bye Visual Basic", attributes); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("UIDefaults Example"); frame.setDefaultCloseOperation(3);/*from w w w .j a v a2 s. co m*/ Container c = frame.getContentPane(); UIManager.put("Button.background", Color.red); UIManager.put("Button.foreground", Color.white); Font f = new Font("Serif", Font.ITALIC, 24); UIManager.put("Button.font", f); JButton north = new JButton("North"); JButton south = new JButton("South"); JButton east = new JButton("East"); JButton west = new JButton("West"); JButton center = new JButton("Center"); c.add(north, BorderLayout.NORTH); c.add(south, BorderLayout.SOUTH); c.add(east, BorderLayout.EAST); c.add(west, BorderLayout.WEST); c.add(center, BorderLayout.CENTER); frame.pack(); frame.show(); }