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[]) throws Exception { JFrame frame = new JFrame("MultiHighlight"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea comp = new JTextArea(5, 20); comp.setText("this is a test"); frame.getContentPane().add(new JScrollPane(comp), BorderLayout.CENTER); String charsToHighlight = "a"; Highlighter h = comp.getHighlighter(); h.removeAllHighlights();/*ww w . jav a2 s . c om*/ String text = comp.getText().toUpperCase(); for (int j = 0; j < text.length(); j += 1) { char ch = text.charAt(j); if (charsToHighlight.indexOf(ch) >= 0) h.addHighlight(j, j + 1, DefaultHighlighter.DefaultPainter); } frame.pack(); frame.setVisible(true); }
From source file:SimpleButtonGroupExample.java
public static void main(String[] args) { // Some choices JRadioButton choice1, choice2, choice3; choice1 = new JRadioButton("Bach: Well Tempered Clavier, Book I"); choice1.setActionCommand("bach1"); choice2 = new JRadioButton("Bach: Well Tempered Clavier, Book II"); choice2.setActionCommand("bach2"); choice3 = new JRadioButton("Shostakovich: 24 Preludes and Fugues"); choice3.setActionCommand("shostakovich"); // A group, to ensure that we only vote for one. final ButtonGroup group = new ButtonGroup(); group.add(choice1);/* w w w. j a va2s . c o m*/ group.add(choice2); group.add(choice3); // A simple ActionListener, showing each selection using the ButtonModel class VoteActionListener implements ActionListener { public void actionPerformed(ActionEvent ev) { String choice = group.getSelection().getActionCommand(); System.out.println("ACTION Choice Selected: " + choice); } } // A simple ItemListener, showing each selection and deselection class VoteItemListener implements ItemListener { public void itemStateChanged(ItemEvent ev) { boolean selected = (ev.getStateChange() == ItemEvent.SELECTED); AbstractButton button = (AbstractButton) ev.getItemSelectable(); System.out .println("ITEM Choice Selected: " + selected + ", Selection: " + button.getActionCommand()); } } // Add listeners to each button ActionListener alisten = new VoteActionListener(); choice1.addActionListener(alisten); choice2.addActionListener(alisten); choice3.addActionListener(alisten); ItemListener ilisten = new VoteItemListener(); choice1.addItemListener(ilisten); choice2.addItemListener(ilisten); choice3.addItemListener(ilisten); // Throw everything together JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = frame.getContentPane(); c.setLayout(new GridLayout(0, 1)); c.add(new JLabel("Vote for your favorite prelude & fugue cycle")); c.add(choice1); c.add(choice2); c.add(choice3); frame.pack(); frame.setVisible(true); }
From source file:MenuActionExample.java
public static void main(String s[]) { MenuActionExample example = new MenuActionExample(); JFrame frame = new JFrame("Action Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(example.menuBar);/*from www . j a v a2 s . com*/ frame.getContentPane().add(example.toolBar, BorderLayout.NORTH); frame.setSize(200, 200); frame.setVisible(true); }
From source file:org.jfree.chart.demo.MemoryUsageDemo.java
public static void main(String args[]) { JFrame jframe = new JFrame("Memory Usage Demo"); MemoryUsageDemo memoryusagedemo = new MemoryUsageDemo(30000); jframe.getContentPane().add(memoryusagedemo, "Center"); jframe.setBounds(200, 120, 600, 280); jframe.setVisible(true);// w ww .j a v a 2 s . c om (memoryusagedemo.new DataGenerator(100)).start(); jframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowevent) { System.exit(0); } }); }
From source file:CustomTreeCellRenderer.java
public static void main(String[] args) { ImageIcon iconWhite = new ImageIcon("white.jpg"); ImageIcon iconBlack = new ImageIcon("black.jpg"); ;//from w w w.jav a2 s .c om JFrame frame = new JFrame(); frame.setContentPane(new JPanel(new BorderLayout())); JTree tree = new JTree(); frame.getContentPane().add(tree); CustomTreeCellRenderer renderer = new CustomTreeCellRenderer(); renderer.setRendererIcon(iconWhite); tree.setCellRenderer(renderer); JPanel panelButtons = new JPanel(); JButton buttonWhite = new JButton(""); buttonWhite.setIcon(iconWhite); JButton buttonBlack = new JButton(""); buttonBlack.setIcon(iconBlack); buttonBlack.addActionListener(e -> { renderer.setRendererIcon(iconBlack); tree.repaint(); }); panelButtons.add(buttonBlack); panelButtons.add(buttonWhite); frame.getContentPane().add(panelButtons, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 500); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); JButton jb1 = new JButton("Hello"); ButtonModel bm = jb1.getModel(); JButton jb2 = new JButton("World"); jb2.setModel(bm);//from www . ja v a2 s . c o m Container c = f.getContentPane(); c.add(jb1, BorderLayout.NORTH); c.add(jb2, BorderLayout.SOUTH); jb1.addActionListener(new MessageActionListener("Selected One")); jb2.addActionListener(new MessageActionListener("Selected Two")); f.pack(); f.show(); }
From source file:CardLayoutDemo.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); CardLayoutDemo demo = new CardLayoutDemo(); demo.addCardsToPane(frame.getContentPane()); frame.pack();// w w w . j ava 2 s . c om frame.setVisible(true); }
From source file:SwingSplitSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JSplitPane Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT); frame.getContentPane().add(splitPane, BorderLayout.CENTER); frame.setSize(300, 200);//from w w w . ja v a 2 s. c om frame.setVisible(true); }
From source file:EnhancedFileTester.java
public static void main(String args[]) { JFrame f = new JFrame("Enhanced File Example"); JPanel j = new EnhancedFileTester(); f.getContentPane().add(j, BorderLayout.CENTER); f.setSize(300, 200);//from ww w . j a v a 2 s . co m f.show(); }
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); aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); aWindow.getContentPane().setBackground(Color.PINK); aWindow.setVisible(true);//from ww w.j av a 2 s.co m }