java - A clickable grid of JLabel boxes -
i new java gui , trying place grid of 7 x 12 jlabels/boxes. need able x , y co-ordinates of each box. when run below code shows every box 0,0... appreciated.
import java.awt.color; import java.awt.dimension; import java.awt.gridlayout; import javax.swing.*; public class gridpanel extends jpanel{ private final int height = 7; private final int width = 12; private final int total_boxes = height * width; jlabel box[]; public gridpanel() { setlayout(new gridlayout(7,12)); box = new jlabel[total_boxes]; (int x = 0;x<box.length;x++){ box[x]=new jlabel(""); box[x].setopaque(true); box[x].setpreferredsize(new dimension(30,30)); box[x].setbackground(color.white); box[x].setborder(borderfactory.createlineborder(color.black)); int = box[x].getx(); int b = box[x].gety(); string test = b + "," + a; box[x].settext(test); } system.out.println(box[45].getx()); (int x = 0;x<box.length;x++) add(box[x]); }
}
Comments
Post a Comment