我的按钮排列不正确……怎么了?
private void loadPuzzleButtons()
{
if (active_puzzle != null)
{
int devider = 5;
int count = 0;
JToggleButton puzzleButton[] = new JToggleButton[active_puzzle.getNumberOfPieces()];
for(int row = 0; row < active_puzzle.getRows(); row++)
{
for(int column = 0; column < active_puzzle.getColumns(); column++)
{
puzzleButton[count] = new JToggleButton(new ImageIcon( active_puzzle.getPieces()[count].getPieceImage() ) );
puzzleButton[count].setLocation(200 + active_puzzle.getPieceWidth() * column + devider * column,
200 + active_puzzle.getPieceHeight() * row + devider * row);
puzzleButton[count].setContentAreaFilled(false);
puzzleButton[count].setBorderPainted(false);
puzzleButton[count].setBorder(null);
mainPuzzlerPanel.add(puzzleButton[count]);
mainPuzzlerPanel.validate();
count++;
}
}
mainPuzzlerPanel.repaint();
}
}
这是输出的照片:http: //i.imgur.com/Zdink2Q.png
对不起,我会给你我的整个代码,但它更大而且我不会这样做......
提前谢谢您,如果您需要更多信息,请询问!
我想给那些不想看到我如何解决问题的人。
private void loadPuzzleButtons()
{
if (active_puzzle != null)
{
int count = 0;
GridLayout puzzleLayout = new GridLayout(active_puzzle.getRows(),active_puzzle.getColumns(),3,3);
puzzlePanel.setLayout(puzzleLayout);
JToggleButton puzzleButton[] = new JToggleButton[active_puzzle.getNumberOfPieces()];
for(int row = 0; row < active_puzzle.getRows(); row++)
{
for(int column = 0; column < active_puzzle.getColumns(); column++)
{
puzzleButton[count] = new JToggleButton(new ImageIcon(active_puzzle.getPieces()[count].getPieceImage()));
puzzleButton[count].setContentAreaFilled(false);
puzzleButton[count].setBorderPainted(false);
puzzleButton[count].setBorder(null);
puzzlePanel.add(puzzleButton[count]);
puzzlePanel.validate();
count++;
}
}
puzzlePanel.repaint();
}
}