Adding a JLabel to JLayeredPane from event listener not dragging.
- by Cody
Ok, So for some reason When I add components to a JLayeredPane in its constructor:
JLabel label = new JLabel();
label.setSize(100,100);
label.setText("This works");
add(label);
It works perfectly fine, but If a add it later in the JLayeredPane's parent EDT it doesnt let me move the objects around but they let me see the objects.
Adding from EDT:
JLabel label = new JLabel();
label.setToolTipText(url.getHost());
label.setIcon(icon);
label.setBorder(new LineBorder(null));
label.setSize(icon.getIconWidth(), icon.getIconHeight());
dressFrame.layeredPane.add(label, JLayeredPane.DRAG_LAYER);
Dragging method:
Component c = findComponentAt(e.getX(), e.getY());
if (c instanceof JLayeredPane) {
pieceSelected = false;
return;
}
Point parentLocation = c.getLocation();
xAdjustment = parentLocation.x - e.getX();
yAdjustment = parentLocation.y - e.getY();
movingPiece = c;
movingPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
pieceSelected = true;