Results 1 to 4 of 4
Thread: Make all buttons the same size
- 03-16-2011, 05:23 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
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); } } }); } }
- 03-22-2011, 05:55 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
In Swing Example enter hallticket no and click the submit button and display marks
- 03-22-2011, 05:57 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
use swings how to add two numbers
- 03-22-2011, 01:22 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Similar Threads
-
How to make buttons vertical
By ninjalord918 in forum AWT / SwingReplies: 2Last Post: 07-29-2010, 09:10 AM -
Help with Buttons
By wld4ubabay in forum New To JavaReplies: 20Last Post: 05-17-2010, 08:13 AM -
I can't make JLabel do what I want (size-wise)
By fletcher in forum AWT / SwingReplies: 9Last Post: 10-15-2009, 04:41 AM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM -
Where To Get Pop Up Buttons
By hitmen in forum AWT / SwingReplies: 7Last Post: 03-26-2009, 04:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks