Ejemplo n.º 1
0
        private void showJList(JScrollPane view, Point pt)
        {
            JList list = (JList)view.Viewport.View;
            Point p    = SwingUtilities.convertPoint(view, pt.x, pt.y, list);
            int   row  = list.locationToIndex(p);

            if (row == -1)
            {
                hide();
                return;
            }
            Rectangle bds = list.getCellBounds(row, row);
            //GetCellBounds returns a width that is the
            //full component width;  we want only what
            //the renderer really needs.
            ListCellRenderer ren          = list.CellRenderer;
            Dimension        rendererSize = ren.getListCellRendererComponent(list, list.Model.getElementAt(row), row, false, false).PreferredSize;

            // fix for possible npe spotted by SCO
            // http://pspsharp.org/forum/viewtopic.php?p=3387#p3387
            if (bds == null)
            {
                hide();
                return;
            }

            bds.width = rendererSize.width;

            if (!bds.contains(p))
            {
                hide();
                return;
            }

            //bds.width = rendererSize.width;
            //if (bds == null || !bds.contains(p)) {
            //    hide();
            //    return;
            //}
            // end "fix for possible npe spotted by SCO"

            if (setCompAndRow(list, row))
            {
                Rectangle   visible = getShowingRect(view);
                Rectangle[] rects   = getRects(bds, visible);
                if (rects.Length > 0)
                {
                    ensureOldPopupsHidden();
                    painter.configure(list.Model.getElementAt(row), view, list, row);
                    showPopups(rects, bds, visible, list, view);
                }
                else
                {
                    hide();
                }
            }
        }