Hi!

I'm trying to create borders around JLabel components. However, the line c[i].setBorder(border) cannot be compiled. Please, help me to improve this code. Thanks!

public void mouseReleased(MouseEvent e) {
        if (Menu.getgroup()) {
            Component[] c = getComponents();
            Border border = LineBorder.createGrayLineBorder();
            for(int i = 0; i < c.length; i++)
            {
                if(c[i] instanceof JLabel)
                {
                    Rectangle selectedLab = c[i].getBounds();
                    if(selection.contains(selectedLab))
                    {
                        c[i].setBorder(border);
                    }
                }
            }
            selection = null;
            repaint();
        }
    }

Ok, the following line ((JComponent)(c[i])).setBorder(border); works! Thanks!

Edited 5 Years Ago by LianaN: n/a

This question has already been answered. Start a new discussion instead.