Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

My java programe is not displaying all the images correctly

$
0
0
Hello,

I have a small problem with my program not displaying images correctly. I have small image(20x20 pixels, white image with a black border)which i want to display 100 time, in a 10x10 grid. Everything looks fine except for the right and bottom hand images which seem to cut off a bit of the image.

I tried to attach the image I am using but I got an error "Error The server returned an error during upload". Like a said it is just a small 20x20 image with a black border.


import java.awt.*;
import javax.swing.*;

public class userGrid{

	JFrame frame;

	JPanel imagePanel;

	GridPanel playerPanel[] = new GridPanel[100]; 	

	public void build(){

		frame = new JFrame();

		imagePanel = new JPanel();
		imagePanel.setLayout(new GridLayout(10,10));

		for(int i = 0; i < 100; i++){
			playerPanel[i] = new GridPanel();
			imagePanel.add(playerPanel[i]);		
		}


		frame.getContentPane().add(BorderLayout.CENTER, imagePanel);

		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(210,210);
		frame.setVisible(true);
	}

	public static void main(String [] args){
		
		userGrid gridTest = new userGrid();
		gridTest.build();
	}
}

class GridPanel extends JPanel{

	public void paintComponent(Graphics g){
		Image image = new ImageIcon("grid.png").getImage();
		g.drawImage(image,0,0,this);
	}
}



line 29 actually reads
frame.setSize(200,200);



I tried adding in extra space but still no joy.

Viewing all articles
Browse latest Browse all 51036

Trending Articles