Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 06:44 PM
Member
 
Join Date: Jul 2007
Posts: 40
Rep Power: 0
trill is on a distinguished road
Default Help with gaps in GridLayout
Hi, I have a grid, with 12 buttons in it. Once displayed there is a small gap inbetween the buttons, maybe 5 pixels. I have been using the setHgap and setVgap methods to try and get rid of this gap but cannot. Can it be done?
Code:
import javax.swing.*;
import java.awt.*;

class MainPanel extends JFrame{

	Container container = getContentPane();
	JPanel gamePanel = new JPanel();

	String[] buttonsImageNames ={

				"bart0.jpg",
				"bart1.jpg",
				"bart2.jpg",
				"bart3.jpg",
				"bart4.jpg",
				"bart5.jpg",
				"bart6.jpg",
				"bart7.jpg",
				"bart8.jpg",
				"bart9.jpg",
				"bart10.jpg",
				"bart11.jpg",
				};
	JButton [] buttonArray = new JButton[buttonsImageNames.length];
	Insets buttons = new Insets(0,0,0,0);
	ImageIcon [] imagesArray = new ImageIcon[buttonsImageNames.length];
	GridLayout layout = new GridLayout(0,1,0,0);


	public MainPanel()

	{
		setTitle("Jake's Cash Machine!");
		setSize(500,430);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		for(int i=0; i<buttonsImageNames.length; i++){
			buttonArray[i] = new JButton(new ImageIcon(buttonsImageNames[i]));
			buttonArray[i].setMargin(buttons);
			gamePanel.add(buttonArray[i]);

		}

		container.setLayout(layout);
		container.add(gamePanel);
		container.setBackground(Color.white);

		System.out.println(layout);

		setVisible (true);

	}
}
Thanks.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-31-2007, 08:20 PM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Code:
import javax.swing.*;
import java.awt.*;

class MainPanelRx extends JFrame{

	Container container = getContentPane();
	JPanel gamePanel = new JPanel();

	String[] buttonsImageNames ={

				"bart0.jpg",
				"bart1.jpg",
				"bart2.jpg",
				"bart3.jpg",
				"bart4.jpg",
				"bart5.jpg",
				"bart6.jpg",
				"bart7.jpg",
				"bart8.jpg",
				"bart9.jpg",
				"bart10.jpg",
				"bart11.jpg",
				};
	JButton [] buttonArray = new JButton[buttonsImageNames.length];
	Insets buttons = new Insets(0,0,0,0);
	ImageIcon [] imagesArray = new ImageIcon[buttonsImageNames.length];
	GridLayout layout = new GridLayout(0,1,0,0);


	public MainPanelRx()

	{
		setTitle("Jake's Cash Machine!");
		setSize(500,430);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Set the gamePanel layout to the GridLayout
		gamePanel.setLayout(layout);
		for(int i=0; i<buttonsImageNames.length; i++){
			buttonArray[i] = new JButton(new ImageIcon(buttonsImageNames[i]));
			buttonArray[i].setMargin(buttons);
			gamePanel.add(buttonArray[i]);

		}

		// gamePanel still has the default FlowLayout which
		// explains the gaps...
		// Let's leave the contentPanes default BorderLayout
//		container.setLayout(layout);
		// and add gamePanel to the center section.
		container.add(gamePanel);
		container.setBackground(Color.white);

		System.out.println(layout);

		setVisible (true);

	}

	public static void main(String[] args) { new MainPanelRx(); }
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SWT GridLayout Java Tip Java Tips 0 01-08-2008 10:04 AM
GridLayout with animation? tojas AWT / Swing 3 11-12-2007 11:16 PM
Use GridLayout in java toby Java Applets 1 08-04-2007 01:44 AM
Gridlayout Marty AWT / Swing 2 05-31-2007 12:48 PM


All times are GMT +2. The time now is 11:57 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org