JLayeredPane 위에 여러 JLabel을 동적으로 이동해야합니다. 문제는 제대로 새로 고쳐지지 않는다는 것입니다. 때때로 그들은 정확하게 움직이며 때로는 전혀 나타나지 않습니다.JLayeredPane에서 JLabel을 이동
내 코드는 다음과 같습니다
JLabel의 추가 패널
JLayeredPane gameBoardPane = new JLayeredPane();
gameBoardPane.setLayout(null);
Dimension gameBoardLabelSize = gameBoardLabel.getPreferredSize();
gameBoardLabel.setBounds(30, 30, gameBoardLabelSize.width, gameBoardLabelSize.height);
gameBoardPane.add(gameBoardLabel, new Integer(10));
gameBoardPane.setAlignmentY(Component.TOP_ALIGNMENT);
// ...
JPanel gamePane = new JPanel();
gamePane.setLayout(new BoxLayout(gamePane, BoxLayout.LINE_AXIS));
gamePane.add(gameBoardPane);
gamePane.add(gameControlPane);
// ...
Container contentPane = getContentPane();
contentPane.add(gamePane, BorderLayout.PAGE_START);
SnLFrame.setSize(720,600);
구축 :
Coordinates position = new Coordinates();
position = convertToCoordinates(blockNumber);
position.x = position.x * 50;
position.y = position.y * 50;
Dimension smallPlayer1IconLabelSize = smallPlayer1IconLabel.getPreferredSize();
smallPlayer1IconLabel.setBounds(position.x, position.y, smallPlayer1IconLabelSize.width, smallPlayer1IconLabelSize.height);
gameBoardPane.add(smallPlayer1IconLabel, new Integer(100));
SnLFrame.invalidate();
SnLFrame.validate();
SnLFrame.repaint();
는 JLabel의 표시 않을 때 위치는 정확하지만, '아무튼 항상 표시하지 마십시오 ... 무엇이 잘못 되었습니까 ...
[이 답변] (http://stackoverflow.com/a/4687759/522444)에서 비슷한 문제를 처리했습니다. 도움이 될지도 모릅니다. –
하지만 더 도움이 필요하면 실행 불가능한 코드 스 니펫을 기반으로 잘못했을 수있는 일을 추측하는 것이 불가능할 수 있으므로 [sscce] (http://sscce.org)를 작성하고 게시하는 것을 고려하십시오. 지금까지 게시했습니다. –