...

View Full Version : Java: Elminating gaps in Gridlayout



jakenoble
02-13-2005, 10:37 PM
Hi all.

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?

Here is my 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);

}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum