Мне нужно динамически перемещать несколько JLabels поверх JLayeredPane. проблема в том, что они не обновляются должным образом. Иногда они двигаются правильно, иногда вообще не появляются.
Мой код выглядит так:
Создание панели
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 );
Добавление JLabel:
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, но оно не всегда показывает его... Что здесь происходит не так...