Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2012, 08:06 PM
tyw0 tyw0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 tyw0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 40 sec
Reputation Power: 0
GUI Java Buttons not resizing?

Hi,
So my problem is that my code at the moment is supposed to create a table of JButtons that resize when the window resizes. Well that is my issue anyway. At the moment, the buttons do appear and the window is able to resize, but the buttons do not resize with the window. Tips on how to correct this would be great. I feel like the problem is in the addButtons method, but I'm not sure what. I did have a friend test this code and it worked(the JButtons resized when the window was), but I cannot get the Buttons to do it on any of my two computers. Again, Thanks for helping.

Code:
import java.awt.ComponentOrientation;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.GridBagConstraints;
import javax.swing.JFrame;
import java.util.Scanner;
import javax.swing.JPanel;
import java.awt.GridLayout;

public class DisplayBoard2 {
public static void addButtons(JPanel panel, GameOfLife game, GridBagConstraints constraints){
/*
This is supposed to be part of the GUI for Conway's game of Life, but the other classes used(GameOfLife and Board) have no issues and the methods used all return proper values. 
*/
		JButton button;
		panel.setLayout(new GridLayout());
		for(int x =0; x<game.getBoard().getRow(); x++){
			for(int y = 0; y<game.getBoard().getCol(); y++){
				button = new JButton();
				constraints.fill = GridBagConstraints.BOTH;
				constraints.gridx = x;
				constraints.gridy = y;
				panel.add(button, constraints);
			}
		}
	}
	
	public static void showGui(){
        Scanner scan = new Scanner(System.in);
        GameOfLife game = new GameOfLife();
        GridBagConstraints constraints = new GridBagConstraints();
        game.createBoard(scan);
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new GridBagLayout());
        constraints.fill = GridBagConstraints.BOTH;
        frame.setSize(400, 400);
        DisplayBoard.addButtons(panel, game, constraints);
        frame.add(panel);
        frame.setVisible(true);      
        }



	public static void main(String[] args){
            	DisplayBoard.showGui();
            	}
		;
	}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > GUI Java Buttons not resizing?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap