Results 1 to 4 of 4
  1. #1
    Matthew1246 is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default Make all buttons the same size

    I want to make the button on the bottom of the screen the same size as the other buttons. In the code:
    Java Code:
    package com;
    
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    public class Boggle extends JFrame {
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		Boggle bog = new Boggle(4);
    	}
    	
    	protected JButton run = new JButton("run");
    	protected JButton[] buttons;
    	public Boggle(int xy)
    	{
    		buttons = Factory.createButtons(xy);
    		setLayout(xy);
    		setListeners();
    	}
    	public JButton[] setLayout(int xy)
    	{
    		setSize(600,600);
    		JPanel bigpanel = new JPanel();
    		BorderLayout gridlayout = new BorderLayout();
    		bigpanel.setLayout(gridlayout);
    		
    		JPanel panel = new JPanel();
    		panel.setLayout(new GridLayout(xy,xy));
    		for(int i = 0; i < xy*xy; i++)
    		{
    			panel.add(buttons[i]);
    		}
    		bigpanel.add(panel);
    		bigpanel.add(run,BorderLayout.SOUTH);
    		add(bigpanel);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setVisible(true);
    		return buttons;
    	}
    	public void setListeners()
    	{
    		for(JButton button: buttons)
    		{
    			button.addActionListener(new ActionListener()
    			{
    				JButton normalColour = new JButton();
    				public void actionPerformed(ActionEvent ev)
    				{
    					JButton button = (JButton)ev.getSource();
    					if(button.getBackground() == Color.blue)
    					{
    						button.setBackground(normalColour.getBackground());
    					}
    					else
    					{
    						button.setBackground(Color.blue);
    					}
    				}
    			});
    		}
    		run.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent ev)
    			{
    				for(int i = 0; i < 4; i++)
    				{
    					double d = Math.random();
    					d = d * 16;
    					int num = (int)d;
    					JButton button = buttons[num];
    					button.setBackground(Color.blue);
    				}
    			}
    		});
    	}
    }

  2. #2
    subbuija is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    In Swing Example enter hallticket no and click the submit button and display marks

  3. #3
    subbuija is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    use swings how to add two numbers

  4. #4
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Make your gridlayout one row deeper and add the bottom button to the grid panel ('panel') rather than the 'bigpanel'.

Similar Threads

  1. How to make buttons vertical
    By ninjalord918 in forum AWT / Swing
    Replies: 2
    Last Post: 07-29-2010, 10:10 AM
  2. Help with Buttons
    By wld4ubabay in forum New To Java
    Replies: 20
    Last Post: 05-17-2010, 09:13 AM
  3. I can't make JLabel do what I want (size-wise)
    By fletcher in forum AWT / Swing
    Replies: 9
    Last Post: 10-15-2009, 05:41 AM
  4. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 05:37 PM
  5. Where To Get Pop Up Buttons
    By hitmen in forum AWT / Swing
    Replies: 7
    Last Post: 03-26-2009, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •