File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Making a good looking grid in Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making a good looking grid in Swing" Watch "Making a good looking grid in Swing" New topic
Author

Making a good looking grid in Swing

Matthieu Saenen
Greenhorn

Joined: Mar 07, 2013
Posts: 1
Hello everyone, at the end of next week I need a Battleship game, but I'm stuck with making a 2d grid. I have to make something like the photo, but i don't even know how to begin on it. In the grid it are all nice squares and they are all nice ligned out, How did they do that?

http://www.imagebam.com/image/687e73241745809


[ScreenShot001.jpg]

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to the Ranch

Fix the sizes of all those squares. Try a grid layout. There are lots of layouts, which you can find about in the Java Tutorials.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Use gradient painting for that colour shading. Draw multiple lines at right angles to each other. (This suggestion is instead of the layout and many squares, not in addition.)
Cameron Miller
Greenhorn

Joined: Jan 10, 2013
Posts: 13

Draw the background, then use two for loops to draw the grid, one for the vertical lines and one for the horizontal lines. E.g.


This would create a 10x10 grid starting at (10, 10).
 
 
subject: Making a good looking grid in Swing