Does anyone know of a good, easy to use, Java Library that will allow me to create an interactive Grid GUI?
Any help is appreciated.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Does anyone know of a good, easy to use, Java Library that will allow me to create an interactive Grid GUI?
Any help is appreciated.
Can you elaborate a bit more on what you mean by an interactive Grid GUI? What I would envision is something like a checkerboard type of grid, where the squares can be moved around (which could be relatively easy to do in principle), but this could be far from what you need.
I'm actually thinking more of something like a Grid of Images that I can swap out. So the user can click on a Cell and change it's Image somehow. Alternatively, I would also like the Cells to be able to contain things like ints or Strings or something that could possibly be edited by the user.
I'm not interested in moving around cells at the moment, but more changing their traits.
Should be quite feasible with just a GridLayout or GridBagLayout. A Visual Guide to Layout Managers
I was playing around with it, drawing rectangles and whatnot. Then I came across an issue. How can I make the JPanel repaint itself every time it is clicked?
import javax.swing.JPanel; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.Point; public class Grid extends JPanel { int rows; int columns; int xCo = -1; int yCo = -1; Point[][] points; public Grid(int r,int c) { rows = r; columns = c; points = new Point[rows][columns]; this.addMouseListener(new UserClick()); } public void paintComponent(Graphics g) { super.paintComponent(g); for(int x=0;x<rows;x++) { for(int y=0;y<columns;y++) { points[x][y] = new Point(x*50,y*50); if(xCo==x && yCo==y) g.fillRect(x*50,y*50,50,50); else g.drawRect(x*50,y*50,50,50); } } xCo = -1; yCo = -1; } public class UserClick extends MouseAdapter { public UserClick() { super(); } public void mouseClicked(MouseEvent e) { Point p = e.getPoint(); System.out.println("The Cell at location "+(int)(p.getX()/50)+","+(int)(p.getY()/50)+" was pressed."); xCo = (int)(p.getX()/50); yCo = (int)(p.getY()/50); } } }
@Override public void mouseClicked(MouseEvent e){ Grid.this.repaint();// }
aussiemcgr (September 15th, 2010)
Glad to be of help.