I have a drag-able JLabel that I'm trying to set that object to be above all other JLabel objects when its dragged. The only method I can find that sets the order is
setComponentZOrder(Component,int)'
But when I Try to use it, I get a large amount of errors printed to the console saying something about an unknown source. How do I fix these errors? I can do it from main, but how do I do it from a mouse listener in another class?
a JLayeredPane named window is defined in Main and a mouse listener in a card class is where I'm looking to set the order.
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
public class Card extends JLabel implements MouseMotionListener
{
private static final long serialVersionUID = 1L;
public Card(ImageIcon icon)
{
super(icon);
super.setFocusable(true);
addMouseMotionListener(this);
}
//@Override
public void mouseDragged(MouseEvent e)
{
// TODO Auto-generated method stub
setBounds((super.getX()+ e.getX()-25) , (super.getY() + e.getY()-25), super.getIcon().getIconWidth(), super.getIcon().getIconHeight());
this.setRequestFocusEnabled(true);
setComponentZOrder(this, TOP); //this causes the errors
repaint();
}
//@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
}//*/