我工作的一个大学项目,我有困难排队组件与电路板的网格。 该板将始终保持为1:1的宽高比但尺寸可以变化。 这是导致在这个我已经试过:
为什么百分比不与我计算出他们排着队是的为1200x1200的实际图片大小?
这是我的布局代码:
public class BoardPanel extends ViewComponent {
public static final int ROWS = 27;
public static final int COLS = 23;
private Board board = new Board();
private BufferedImage background = ResourceLoader.openImage("images/board.jpg");
public BoardPanel() {
this.add(board, "pos 4.5% 4.5%, width 76.5%, height 91%");
}
@Override
public void paintContent(Graphics2D g) {
g.drawImage(background, 0, 0, getHeight(), getHeight(), null);
}
private class Board extends ViewComponent {
public Board() {
setLayout(new GridLayout(ROWS, COLS, 1, 1));
for (int row = 0; row < ROWS; row++)
for (int col = 0; col < COLS; col++)
this.add(new Location(row, col));
}
}
}