List of usage examples for javax.swing JFrame getContentPane
public Container getContentPane()
contentPane
object for this frame. From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Sharing Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextArea textarea1 = new JTextArea(); Document document = textarea1.getDocument(); JTextArea textarea2 = new JTextArea(document); JTextArea textarea3 = new JTextArea(document); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(new JScrollPane(textarea1)); content.add(new JScrollPane(textarea2)); content.add(new JScrollPane(textarea3)); frame.setSize(300, 400);//w w w.ja va 2 s . c o m frame.setVisible(true); }
From source file:com.jaxzin.iraf.demo.Main.java
public static void main(String[] args) { final JFreeChart chart = ChartFactory.createHistogram("Probability of Values", "Value", "Probability", createData(COUNT), PlotOrientation.VERTICAL, false, true, true); // Customize the chart customizeChart(chart);/*from w ww . j a v a 2 s . c o m*/ final JPanel panel = new ChartPanel(chart, true); final JFrame frame = new JFrame("Demo"); frame.getContentPane().add(panel); setupJFrame(frame); java.util.Timer t = new java.util.Timer(); t.schedule(new DataUpdater(chart), DELAY, DELAY); }
From source file:Main.java
public static void main(String[] args) { SpringLayout layout = new SpringLayout(); JPanel p = new JPanel(layout); p.setBorder(BorderFactory.createLineBorder(Color.GREEN, 10)); JLabel l1 = new JLabel("label: width=90%", SwingConstants.CENTER); l1.setBorder(BorderFactory.createLineBorder(Color.RED, 1)); JButton l2 = new JButton("button: width=50%"); Spring panelw = layout.getConstraint(WIDTH, p); SpringLayout.Constraints c1 = layout.getConstraints(l1); c1.setX(Spring.constant(0));/*from www. j av a2s.c om*/ c1.setY(Spring.constant(20)); c1.setWidth(Spring.scale(panelw, 0.9f)); p.add(l1); SpringLayout.Constraints c2 = layout.getConstraints(l2); c2.setWidth(Spring.scale(panelw, 0.5f)); layout.putConstraint(SOUTH, l2, -20, SOUTH, p); layout.putConstraint(EAST, l2, -20, EAST, p); p.add(l2); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(p); f.setSize(320, 240); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int TIMER_DELAY = 2000; String[] data = { "A", "B", "C", "D" }; DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(data); JComboBox<String> combobox = new JComboBox<>(model); JList<String> jlist = new JList<>(model); new Timer(TIMER_DELAY, new ActionListener() { private int count = 0; public void actionPerformed(ActionEvent e) { model.addElement("count: " + count); count++;/* w w w.ja v a 2 s . c om*/ } }).start(); JPanel comboPanel = new JPanel(); comboPanel.add(combobox); JPanel listPanel = new JPanel(); listPanel.add(new JScrollPane(jlist)); JPanel panel = new JPanel(new GridLayout(1, 0)); panel.add(comboPanel); panel.add(listPanel); panel.setPreferredSize(new Dimension(400, 200)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(panel); f.pack(); f.setVisible(true); }
From source file:InternalFrameTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Internal Frame Listener"); Container contentPane = frame.getContentPane(); JLayeredPane desktop = new JDesktopPane(); desktop.setOpaque(false);//from w w w . ja v a 2 s . co m desktop.add(createLayer("One"), JLayeredPane.POPUP_LAYER); desktop.add(createLayer("Two"), JLayeredPane.DEFAULT_LAYER); desktop.add(createLayer("Three"), JLayeredPane.PALETTE_LAYER); contentPane.add(desktop, BorderLayout.CENTER); frame.setSize(300, 300); frame.show(); }
From source file:Main.java
public static void main(String[] args) { Object[][] rowData = { { "Hello", "World" } }; Object[] columnNames = { "A", "B" }; JTable table;//from w w w .j a v a 2 s . c om DefaultTableModel model; model = new DefaultTableModel(rowData, columnNames); table = new JTable(); table.setModel(model); JButton add = new JButton("Add"); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.addRow(rowData[0]); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(add, BorderLayout.SOUTH); c.add(new JScrollPane(table), BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new BorderLayout()); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Box rowTwo = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); rowTwo.add(new JPasswordField()); content.add(rowOne, BorderLayout.NORTH); content.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);/*from w ww. j av a2 s .c o m*/ f.setVisible(true); }
From source file:MnemonicSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mnemonics"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(1, 0)); JButton button1 = new JButton("Warning"); button1.setMnemonic(KeyEvent.VK_W); content.add(button1);/* w w w. j av a 2 s .c o m*/ JButton button2 = new JButton("Warning"); button2.setMnemonic(KeyEvent.VK_H); content.add(button2); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextField tf = new JTextField("press <enter>", 20); tf.setHorizontalAlignment(JTextField.RIGHT); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int old = tf.getHorizontalAlignment(); if (old == JTextField.LEFT) tf.setHorizontalAlignment(JTextField.RIGHT); if (old == JTextField.RIGHT) tf.setHorizontalAlignment(JTextField.CENTER); if (old == JTextField.CENTER) tf.setHorizontalAlignment(JTextField.LEFT); }/*from w w w.java 2s . co m*/ }); JFrame frame = new JFrame("JTextFieldExample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new java.awt.FlowLayout()); frame.getContentPane().add(tf); frame.setSize(275, 75); frame.setVisible(true); tf.requestFocus(); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GridLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(3, 0)); for (int i = 1; i <= 9; i++) { buttonPanel.add(new JButton("Button " + i)); }// www . jav a2 s. c om contentPane.add(buttonPanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }