I have been trying to create to create a Custom Renderer for a ComboBox
that allows me to have a clickable JLabel
containing an Icon
in every cell.
The Problem i am having is, that no MouseEvent
seems to reach the components inside of the JList
that is part of the BasicComboPopup
.
This is the Component that returns the Component that should be rendered:
@Override
public Component getListCellRendererComponent( final JList<? extends E> list, final @Nullable E value, final int index,
final boolean isSelected, final boolean cellHasFocus )
{
final Component plafComponent = plafRenderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
if ( value instanceof String && value.equals( BasicComboBox.SEPARATOR ) )
{
return new JSeparator( SwingConstants.HORIZONTAL );
}
final JPanel panel = new JPanel( new MigLayout( new LC().fill().flowX().insetsAll( "0" ) ) );
final Optional<JLabel> cast = Optionals.cast( plafComponent, JLabel.class );
cast.ifPresent( label ->
{
label.setText( converter.apply( value ) );
panel.add( label, new CC().growX().pushX() );
panel.setBackground( label.getBackground() );
} );
if ( decideIfShowIcon.apply( value ) )
{
final IconLabelWithAction<E> iconLabel = new IconLabelWithAction<>( icon, onClickIconConsumer, value );
panel.add( iconLabel, new CC().alignX( "center" ).gapRight( "5" ) );
iconLabel.addMouseListener( new MouseAdapter()
{
@Override
public void mouseReleased( final MouseEvent e )
{
System.out.println( "Never happens" );
}
} );
}
return panel;
}
Drawing the icons works fine, they are just not clickable, I am uncertain why.
I have also tried catching the events on the JList
, not even that worked.