List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolBar = new JToolBar(); Action a = new AbstractAction("Demo") { public void actionPerformed(ActionEvent e) { System.out.println("Action taken."); }// w ww . java2s .c o m }; JButton b = toolBar.add(a); b.setText("Demo Button"); b.setToolTipText("Press me to take action."); JMenu mainMenu = new JMenu("Menu"); JMenuItem mi = mainMenu.add(a); mi.getAccessibleContext().setAccessibleName("Menu item"); JMenuBar mb = new JMenuBar(); mb.add(mainMenu); setJMenuBar(mb); JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.setPreferredSize(new Dimension(200, 100)); pane.add(toolBar, BorderLayout.NORTH); setContentPane(pane); pack(); setVisible(true); }
From source file:ScrollBarColorSelect.java
public ScrollBarColorSelect() { setTitle("ColorSelect"); setSize(300, 200);/*from w w w . j a va 2s.c om*/ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = getContentPane(); JPanel p = new JPanel(); p.setLayout(new GridLayout(3, 2, 3, 3)); p.add(redLabel = new JLabel("Red 0")); p.add(red = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255)); red.setBlockIncrement(16); red.addAdjustmentListener(this); p.add(greenLabel = new JLabel("Green 0")); p.add(green = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255)); green.setBlockIncrement(16); green.addAdjustmentListener(this); p.add(blueLabel = new JLabel("Blue 0")); p.add(blue = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255)); blue.setBlockIncrement(16); blue.addAdjustmentListener(this); contentPane.add(p, "South"); colorPanel = new JPanel(); colorPanel.setBackground(new Color(0, 0, 0)); contentPane.add(colorPanel, "Center"); }
From source file:Main.java
public Main() { JPanel panel = new JPanel(); panel.setLayout(null); model = new DefaultListModel(); list = new JList(model); list.setBounds(150, 30, 220, 150);/*from w ww . j a v a2 s . co m*/ JButton okButton = new JButton("Ok"); okButton.setBounds(30, 35, 80, 25); okButton.addActionListener(this); panel.add(okButton); panel.add(list); add(panel); setSize(420, 250); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:Main.java
public Main() { JPanel northPanel = new JPanel(); northPanel.setLayout(new GridLayout(3, 1, 0, 5)); northPanel.add(label);/*from w w w . j a va2 s . c om*/ northPanel.add(button); northPanel.add(comboBox); add(northPanel, BorderLayout.NORTH); JPanel southPanel = new JPanel(); ItemHandler handler = new ItemHandler(); southPanel.setLayout(new GridLayout(1, radio.length)); ButtonGroup group = new ButtonGroup(); for (int i = 0; i < radio.length; i++) { radio[i] = new JRadioButton(strings[i]); radio[i].addItemListener(handler); group.add(radio[i]); southPanel.add(radio[i]); } add(southPanel, BorderLayout.SOUTH); setSize(300, 200); setVisible(true); radio[0].setSelected(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public Main() { super("Demostrating BoxLayout"); final int SIZE = 3; Container c = getContentPane(); c.setLayout(new BorderLayout(30, 30)); Box boxes[] = new Box[4]; boxes[0] = Box.createHorizontalBox(); boxes[1] = Box.createVerticalBox(); boxes[2] = Box.createHorizontalBox(); boxes[3] = Box.createVerticalBox(); for (int i = 0; i < SIZE; i++) boxes[0].add(new JButton("boxes[0]: " + i)); for (int i = 0; i < SIZE; i++) { boxes[1].add(Box.createVerticalStrut(25)); boxes[1].add(new JButton("boxes[1]: " + i)); }/*w w w .j a v a2 s . c o m*/ for (int i = 0; i < SIZE; i++) { boxes[2].add(Box.createHorizontalGlue()); boxes[2].add(new JButton("boxes[2]: " + i)); } for (int i = 0; i < SIZE; i++) { boxes[3].add(Box.createRigidArea(new Dimension(12, 8))); boxes[3].add(new JButton("boxes[3]: " + i)); } JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); for (int i = 0; i < SIZE; i++) { panel.add(Box.createGlue()); panel.add(new JButton("panel: " + i)); } c.add(boxes[0], BorderLayout.NORTH); c.add(boxes[1], BorderLayout.EAST); c.add(boxes[2], BorderLayout.SOUTH); c.add(boxes[3], BorderLayout.WEST); c.add(panel, BorderLayout.CENTER); setSize(350, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:ScrollDemo.java
public void init() { JRadioButton form[][] = new JRadioButton[12][5]; String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" }; String categories[] = { "Household", "Office", "Extended Family", "Company (US)", "Company (World)", "Team", "Will", "Birthday Card List", "High School", "Country", "Continent", "Planet" }; JPanel p = new JPanel(); p.setSize(600, 400);//from w w w . ja v a 2 s.c o m p.setLayout(new GridLayout(13, 6, 10, 0)); for (int row = 0; row < 13; row++) { ButtonGroup bg = new ButtonGroup(); for (int col = 0; col < 6; col++) { if (row == 0) { p.add(new JLabel(counts[col])); } else { if (col == 0) { p.add(new JLabel(categories[row - 1])); } else { form[row - 1][col - 1] = new JRadioButton(); bg.add(form[row - 1][col - 1]); p.add(form[row - 1][col - 1]); } } } } scrollpane = new JScrollPane(p); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:TicTacToe.java
public void init() { JPanel p = new JPanel(); p.setLayout(new GridLayout(2, 2)); p.add(new JLabel("Rows", JLabel.CENTER)); p.add(rows);// w w w.j av a2s .c om p.add(new JLabel("Columns", JLabel.CENTER)); p.add(cols); Container cp = getContentPane(); cp.add(p, BorderLayout.NORTH); JButton b = new JButton("go"); b.addActionListener(new BL()); cp.add(b, BorderLayout.SOUTH); }
From source file:Main.java
private JPanel create() { JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true);/*from w w w . ja v a 2 s. c o m*/ layout.setAutoCreateContainerGaps(true); GroupLayout.ParallelGroup parallel = layout.createParallelGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(parallel)); GroupLayout.SequentialGroup sequential = layout.createSequentialGroup(); layout.setVerticalGroup(sequential); for (int i = 0; i < NUM; i++) { labels[i] = new JLabel(String.valueOf(i + 1), JLabel.RIGHT); fields[i] = new JTextField(String.valueOf("" + (i + 1))); labels[i].setLabelFor(fields[i]); parallel.addGroup(layout.createSequentialGroup().addComponent(labels[i]).addComponent(fields[i])); sequential.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(labels[i]) .addComponent(fields[i])); layout.linkSize(SwingConstants.HORIZONTAL, labels[i], labels[0]); } return panel; }
From source file:MonthPanel.java
public MonthPanel(int month, int year) { this.month = month; this.year = year; JPanel monthPanel = new JPanel(true); monthPanel.setLayout(new BorderLayout()); monthPanel.add(createTitleGUI(), BorderLayout.NORTH); monthPanel.add(createDaysGUI(), BorderLayout.SOUTH); this.add(monthPanel); }
From source file:MonthPanel.java
protected JPanel createTitleGUI() { JPanel titlePanel = new JPanel(true); titlePanel.setLayout(new FlowLayout()); titlePanel.setBackground(Color.WHITE); JLabel label = new JLabel(monthNames[month] + " " + year); label.setForeground(SystemColor.activeCaption); titlePanel.add(label, BorderLayout.CENTER); return titlePanel; }