Closed mokun closed 3 years ago
It doesn't matter what kind of objects you are using as combobox data. Visual representation is always defined by the renderer, so you can adjust anything you want through it. This part is coming from Swing: https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer
If you don't want to break the default view - you can simply use default WebLaF renderer and provide custom settings in it:
comboBox.setRenderer ( new WebComboBoxRenderer ()
{
@Override
protected int horizontalAlignmentForValue ( final ListCellParameters parameters )
{
return JLabel.CENTER;
}
} );
You can also provide this and a lot of other visual settings through a custom style for the renderer component, you can look at the default combobox.xml
style to see where those are located:
<!-- Default cell renderer label -->
<style type="styledlabel" id="renderer" />
<!-- Selected value renderer label -->
<style type="styledlabel" id="box-renderer" extends="renderer" padding="2,4,2,4" />
<!-- Popup list cell renderer label -->
<style type="styledlabel" id="list-renderer" extends="renderer" padding="4,6,4,6" />
Style box-renderer
is used for the value in the combobox itself, style list-renderer
is used for values displayed in the combobox popup list. As you can see those are simply default WebStyledLabel
styles with some padding applied.
I see. It works now. Thanks !
I've been trying to center the string text of the elements in WebComboBox but can't.
It's left aligned by default.
If the elements are objects and not strings, does it make it harder to do so ?
Appreciate for any hints !