// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    DefaultListModel<String> model = new DefaultListModel<>();
    model.addElement("Name1-comment");
    model.addElement("Name2-test");
    model.addElement("asdfasd");
    model.addElement("35663456345634563456");
    model.addElement("jklghlghjlghjlghlgh");
    model.addElement("Name0-testaa");
    model.addElement("nmvnvnvbnvbmnvbnmvbnmbvmnvbn");
    model.addElement("asdfffasddddddddddddddddd");
    model.addElement("asdfasdfasdfasdfas");
    model.addElement("4352345123452345234523452345234534");

    JList<String> list = new RollOverList<>(model);
    add(new JScrollPane(list));
    setPreferredSize(new Dimension(320, 240));
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

class RollOverList<E> extends JList<E> {
  protected static final Color ROLLOVER_BACKGROUND = new Color(0xDC_F0_FF);
  private transient RollOverListener rollOverListener;
  protected int rollOverRowIndex = -1;

  protected RollOverList(ListModel<E> model) {
    super(model);
  }

  @Override public void updateUI() {
    removeMouseListener(rollOverListener);
    removeMouseMotionListener(rollOverListener);
    setSelectionBackground(null); // Nimbus
    super.updateUI();
    rollOverListener = new RollOverListener();
    addMouseMotionListener(rollOverListener);
    addMouseListener(rollOverListener);
    setCellRenderer(new RollOverCellRenderer());
  }

  private class RollOverCellRenderer implements ListCellRenderer<E> {
    private final ListCellRenderer<? super E> renderer = new DefaultListCellRenderer();

    @Override public Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) {
      Component c = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      if (index == rollOverRowIndex) {
        c.setBackground(ROLLOVER_BACKGROUND);
        if (isSelected) {
          c.setForeground(Color.BLACK);
        }
        // c.setForeground(getSelectionForeground());
        // c.setBackground(getSelectionBackground());
      }
      return c;
    }
  }

  private class RollOverListener extends MouseAdapter {
    @Override public void mouseExited(MouseEvent e) {
      rollOverRowIndex = -1;
      repaint();
    }

    @Override public void mouseMoved(MouseEvent e) {
      int row = locationToIndex(e.getPoint());
      if (row != rollOverRowIndex) {
        Rectangle rect = getCellBounds(row, row);
        if (rollOverRowIndex >= 0) {
          rect.add(getCellBounds(rollOverRowIndex, rollOverRowIndex));
        }
        rollOverRowIndex = row;
        repaint(rect);
      }
    }
  }
}

@@ -467,23 +467,27 @@
 lement(%22
-asdfasd
+11111111111
 %22);%0A    
@@ -554,27 +554,26 @@
 nt(%22
-jklghlghjlghjlghlgh
+222222222222222222
 %22);%0A
@@ -604,14 +604,17 @@
 me0-
-testaa
+333333333
 %22);%0A
@@ -639,36 +639,28 @@
 nt(%22
-nmvnvnvbnvbmnvbnmvbnmbvmnvbn
+44444444444444444444
 %22);%0A
@@ -685,33 +685,24 @@
 nt(%22
-asdfffasddddddddddddddddd
+5555555555555555
 %22);%0A
@@ -727,26 +727,31 @@
 nt(%22
-asdfasdfasdfasdfas
+66666666666666666666666
 %22);%0A
@@ -1677,84 +1677,8 @@
 %3E %7B%0A
-  protected static final Color ROLLOVER_BACKGROUND = new Color(0xDC_F0_FF);%0A
   pr
@@ -1701,22 +1701,25 @@
 RollOver
-Listen
+CellHandl
 er rollO
@@ -1725,55 +1725,15 @@
 Over
-Listener;%0A  protected int rollOverRowIndex = -1
+Handler
 ;%0A%0A 
@@ -1862,38 +1862,37 @@
 istener(rollOver
-Listen
+Handl
 er);%0A    removeM
@@ -1910,38 +1910,37 @@
 istener(rollOver
-Listen
+Handl
 er);%0A    setSele
@@ -2006,22 +2006,21 @@
 rollOver
-Listen
+Handl
 er = new
@@ -2028,22 +2028,25 @@
 RollOver
-Listen
+CellHandl
 er();%0A  
@@ -2070,38 +2070,37 @@
 istener(rollOver
-Listen
+Handl
 er);%0A    addMous
@@ -2117,22 +2117,21 @@
 rollOver
-Listen
+Handl
 er);%0A   
@@ -2151,34 +2151,23 @@
 rer(
-new R
+r
 ollOver
-CellRenderer()
+Handler
 );%0A 
@@ -2198,22 +2198,42 @@
 OverCell
-Re
+Ha
 nd
+l
 er
+ extends MouseAdapt
 er imple
@@ -2260,16 +2260,123 @@
 er%3CE%3E %7B%0A
+    private final Color rolloverBackground = new Color(0xDC_F0_FF);%0A    private int rollOverRowIndex = -1;%0A
     priv
@@ -2777,27 +2777,26 @@
 und(
-ROLLOVER_BACKGROUND
+rolloverBackground
 );%0A 
@@ -3012,68 +3012,8 @@
   %7D%0A
-  %7D%0A%0A  private class RollOverListener extends MouseAdapter %7B
 %0A   

combine ListCellRenderer and MouseAdapter