Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:41:28+00:00 2026-06-05T14:41:28+00:00

Currently, I have a Jlist with a custom CellRenderer as follows. I attached a

  • 0

Currently, I have a Jlist with a custom CellRenderer as follows. I attached a custom MouseListener in order to capture hover events and, later on, double click events; but the events weren’t being fired when I added them this way. After 20 minutes, I found out it was because the JList was blocking the events from reaching the individual list items. Is there any way I can force the JList to forward the mouse events to its children elements, or is there a better way of doing this.

My CellRenderer:

public class FriendRenderer extends DefaultListCellRenderer {

    private static final long serialVersionUID = 1L;

    public Component getListCellRendererComponent(JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean hasFocus) {

        Friend friend = (Friend)value;

        JLabel label = new JLabel(friend.getName());

        JPanel mainOuterPanel = new JPanel();
        mainOuterPanel.setLayout(new BorderLayout());

        /* Adding components to mainOuterPanel... */

        /* Here is where I add the custom MouseListener */
        mainOuterPanel.addMouseListener(new ListItemMouseListener());

        return(mainOuterPanel);
    }

}

My MouseListener:

public class ListItemMouseListener implements MouseListener{

    @Override
    public void mouseClicked(MouseEvent e) {}

    @Override
    public void mousePressed(MouseEvent e) {}

    @Override
    public void mouseReleased(MouseEvent e) {}

    @Override
    public void mouseEntered(MouseEvent e) {
        Component source = e.getComponent();
        source.setBackground(new Color(102, 99, 86));
        System.out.println("Mouse entered on " + source.toString());
    }

    @Override
    public void mouseExited(MouseEvent e) {
        Component source = e.getComponent();
        source.setBackground(null);
        System.out.println("Mouse Exited on " + source.toString());
    }
}

Where I build my JList in my JFrame:

private JList getFriendsList(){
    friendsList = new JList(getFriendsListModel()); //TODO Actually fill with data
    friendsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    friendsList.setLayoutOrientation( JList.VERTICAL );
    friendsList.addListSelectionListener(new FriendsListSelectionListener());
    friendsList.setCellRenderer(new FriendRenderer());
    return friendsList;
}

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:41:31+00:00Added an answer on June 5, 2026 at 2:41 pm

    Add the listener to the list and use the list methods to convert the point to a row.

    The reason it is not working when added to the renderer, is that the render is really only used for ..rendering. It is like a ‘template’ used to paint the list item (& every other visible list item) before the item(s) appear on-screen.


    ..access the cells .. in order to change the background..

    Configure the ListCellRenderer to handle that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have a JList listen to list selection listener. private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt)
Currently have a drop down menu that is activated on a hover (from display:none
I currently have a list box set up as follows: .xaml: <ListBox Name=DetailsList ItemsSource={Binding}
Currently have a custom Form Element View: class Apply_View_Helper_JQueryUiFormRadio extends Zend_View_Helper_FormElement My form is
Currently have a database formatted as follows: id (unique id) url: http://domain.com/page.html Urls are
I have two instances of JList currently, one being priceList and the other is
Currently have WebSphere with some EJBs and defined custom user registry based on DB.
I currently have the following script: http://jsfiddle.net/oshirowanen/mnXdv/ Which works fine, i.e. if a click
Currently have password protection on my main and sub directories, however I'd like to
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.