mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

how do this in Webcombox #700

Closed wyj3531 closed 2 years ago

wyj3531 commented 2 years ago

image

i just want to this three place in different style,like textSize,textColor, .in getListCellRendererComponent method can not do it. how to do it.

mgarin commented 2 years ago

You can use WebComboBoxRenderer which has separate methods you can override for various text settings. For instance specifically for text style, size and color:

combobox.setRenderer ( new WebComboBoxRenderer ()
{
    @Override
    protected Font fontForValue ( final ListCellParameters parameters )
    {
        return super.fontForValue ( parameters );
    }

    @Override
    protected Color foregroundForValue ( final ListCellParameters parameters )
    {
        return super.foregroundForValue ( parameters );
    }
} );

You can specify generics for WebComboBoxRenderer if you know particular types of your combobox values, that will provide you the specific rendered value with correct type via ListCellParameters.

mgarin commented 2 years ago

If you aren't using custom WebLaF renderer - you can check the Swing tutorial on combobox that explains how it can be done: https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html