List of usage examples for javax.swing JPanel add
public Component add(Component comp)
From source file:SharedDataBetweenComboBoxSample.java
public static void main(String args[]) { final String labels[] = { "A", "B", "C", "D", "E", "F", "G" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setEditable(true);//from w w w .j a v a 2 s. com JComboBox comboBox2 = new JComboBox(model); comboBox2.setEditable(true); panel.add(comboBox1); panel.add(comboBox2); frame.add(panel, BorderLayout.NORTH); JButton button = new JButton("Add"); frame.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.addElement("New Added"); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT)); statusBar.setBorder(new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 4, 4, 4))); final JLabel status = new JLabel(); statusBar.add(status); JLabel content = new JLabel("Content in the middle"); content.setHorizontalAlignment(JLabel.CENTER); final JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(content);//from w ww .j a v a 2 s .c o m frame.add(statusBar, BorderLayout.SOUTH); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { status.setText(frame.getWidth() + "x" + frame.getHeight()); } }); frame.setBounds(20, 20, 200, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS); container.setLayout(layout);// w w w . j a v a 2s .co m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.PAGE_AXIS); container.setLayout(layout);//w w w. j a va 2s. c o m for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.LINE_AXIS); container.setLayout(layout);// w w w . java 2s .c om for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int x = 5;/*from w ww .j a v a2 s . com*/ int y = 5; JPanel panel = new JPanel(); panel.setLayout(new GridLayout(x, y)); for (int i = 0; i < x * y; i++) { JButton button = new JButton(String.valueOf(i)); button.setPreferredSize(new Dimension(100, 100)); panel.add(button); } JPanel container = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); container.add(panel); JScrollPane scrollPane = new JScrollPane(container); f.getContentPane().add(scrollPane); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:CircleLayoutDemo.java
public static void main(String a[]) { JFrame frame = new JFrame(); JPanel circle = new JPanel(); circle.setLayout(new CircleLayout(true)); for (int i = 0; i < 10; i++) { circle.add(new JLabel("circle_" + i * 7)); }/* w ww . j av a 2 s . c om*/ frame.setContentPane(circle); frame.setSize(200, 400); frame.setVisible(true); }
From source file:AlignY.java
public static void main(String args[]) { JFrame frame = new JFrame("Y Alignment"); JPanel contentPane = (JPanel) frame.getContentPane(); BoxLayout layout = new BoxLayout(contentPane, BoxLayout.X_AXIS); contentPane.setLayout(layout);// w w w. ja v a 2 s . c o m JButton button = new JButton("0.0"); button.setAlignmentY(Component.TOP_ALIGNMENT); contentPane.add(button); button = new JButton("1.0"); button.setAlignmentY(Component.BOTTOM_ALIGNMENT); contentPane.add(button); button = new JButton("0.5"); button.setAlignmentY(Component.CENTER_ALIGNMENT); contentPane.add(button); frame.setSize(200, 100); frame.show(); }
From source file:FlatCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame("Flat CheckBox Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); panel.setBorder(border);//from w w w . ja v a2 s .c o m JCheckBox check = new JCheckBox("Anchovies"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Garlic"); panel.add(check); check = new JCheckBox("Onions"); check.setBorderPaintedFlat(true); panel.add(check); check = new JCheckBox("Pepperoni"); panel.add(check); check = new JCheckBox("Spinach"); check.setBorderPaintedFlat(true); panel.add(check); JButton button = new JButton("Submit"); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Runnable r = new Runnable() { @Override/*w ww. j av a 2s . c o m*/ public void run() { JPanel gui = new JPanel(); final AnimatedImage[] tiles = new AnimatedImage[2]; for (int ii = 0; ii < tiles.length; ii++) { tiles[ii] = new AnimatedImage(); gui.add(new JLabel(new ImageIcon(tiles[ii]))); } ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < tiles.length; i++) { tiles[i].paintImage(); gui.repaint(); } } }; Timer timer = new Timer(50, listener); timer.start(); JOptionPane.showMessageDialog(null, gui); timer.stop(); } }; SwingUtilities.invokeLater(r); }