ListComboBox: change the fontsize of the listitems

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

ListComboBox: change the fontsize of the listitems

Postby td84 » Wed Dec 06, 2017 6:36 am

Hello,

i would like to change the fontsize of the items in a com.jidesoft.combobox.ListComboBox.
My try was to get the renderer and set the font of the Component returned by the renderer, but i get a nullpointerexception:
Can You help me?

Code: Select all
public class MyListComboBox extends ListComboBox {
   private ListCellRenderer superRenderer;
   private ListCellRenderer myRenderer;
   

   public MyListComboBox(Object[] objects, Class<?> clazz) {
      super(objects, clazz);
      initMyRenderer();
   }
   
   
   public MyListComboBox(ComboBoxModel model) {
      super(model);
      initMyRenderer();
   }
   
   
   public void initMyRenderer() {
      myRenderer = new ListCellRenderer() {
         @Override public Component getListCellRendererComponent(JList list, Object value, int index,
                      boolean isSelected, boolean cellHasFocus) {
            System.out.format("\nmyRenderer() - super: [%s]\n", superRenderer);
            Component comp = superRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            comp.setFont( new Font("Segoe UI", Font.PLAIN, 14) );
            return comp;
         }
      };
   }
   
   
   @Override public ListCellRenderer getRenderer() {
      superRenderer = super.getRenderer();
      System.out.format("\ngetRenderer() - super: [%s]\n", superRenderer);
      return myRenderer;
   }
}


Thanx in advance,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: ListComboBox: change the fontsize of the listitems

Postby JIDE Support » Wed Dec 06, 2017 9:48 am

Try ListExComboBox because that's one we will maintain moving forward.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: ListComboBox: change the fontsize of the listitems

Postby td84 » Wed Dec 06, 2017 4:50 pm

JIDE Support wrote:Try ListExComboBox because that's one we will maintain moving forward.


Ok, thanx. Do you mean instead extends ListComboBox i should write extends ListExComboBox and it will work?
Could you please post a small example?

Thank you,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: ListComboBox: change the fontsize of the listitems

Postby JIDE Support » Wed Dec 06, 2017 11:07 pm

You had the code. Just replace ListComboBox with ListExComboBox.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: ListComboBox: change the fontsize of the listitems

Postby td84 » Thu Dec 07, 2017 9:57 am

JIDE Support wrote:You had the code. Just replace ListComboBox with ListExComboBox.


Thanx it worked, but now i have 2 other issues:
1) the Look&Feel of the dropdown changed from the "white box" to the "grey box" (see attachments). I would like to have the "white box" (while using ListExComboBox).
2) if i select something in the dropdown, the text that is sowing in the "gery box" has still the old font shape. (but the text in the dropdown-list has the new font shape)

Can you help me with these?

Thanx again,
Daniel
Attachments
old.JPG
"white box"
old.JPG (8.17 KiB) Viewed 50114 times
new.JPG
"grey box"
new.JPG (8.43 KiB) Viewed 50114 times
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: ListComboBox: change the fontsize of the listitems

Postby JIDE Support » Thu Dec 07, 2017 10:30 am

Make it editable.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: ListComboBox: change the fontsize of the listitems

Postby td84 » Thu Dec 07, 2017 11:50 am

JIDE Support wrote:Make it editable.

Thanx, but i set it deliberately noneditable. In the old Version (with ListComboBox) i got the right UI even if i set it to noneditable.
Is it no way to keep it noneditable and have the old L&F?
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: ListComboBox: change the fontsize of the listitems

Postby JIDE Support » Thu Dec 07, 2017 12:43 pm

There is no way to do that. That's how JComboBox looks as well.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: ListComboBox: change the fontsize of the listitems

Postby td84 » Fri Dec 08, 2017 6:20 am

JIDE Support wrote:There is no way to do that. That's how JComboBox looks as well.


Ok, i understand. Do you allow me a last question ?
How can i change the fontsize of the selected text, that is showing in the Textfield not in the Dropdown-list?
I mean: i would like to set the size of "Yes" to 14. Actually it's 12 as you can see on the picture.

Thank you again,
Daniel
Attachments
new.JPG
new.JPG (8.43 KiB) Viewed 50105 times
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: ListComboBox: change the fontsize of the listitems

Postby JIDE Support » Fri Dec 08, 2017 10:24 am

That's the renderer. Non-editable combobox doesn't have a text field. It used the same list renderer to render the text on the combobox.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: ListComboBox: change the fontsize of the listitems

Postby td84 » Fri Dec 08, 2017 12:15 pm

JIDE Support wrote:That's the renderer. Non-editable combobox doesn't have a text field. It used the same list renderer to render the text on the combobox.


Ok, than maybe i make something wrong, because the "Yes" in the combobox is still is smaller, then in the dropdown-list.
I also set a bold fontface for dropdown-list, but the text in the combobox doesn't appear in bold.
Could you help to fix it?

Thanx,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: ListComboBox: change the fontsize of the listitems

Postby td84 » Sat Dec 09, 2017 8:00 am

td84 wrote:
JIDE Support wrote:That's the renderer. Non-editable combobox doesn't have a text field. It used the same list renderer to render the text on the combobox.


Ok, than maybe i make something wrong, because the "Yes" in the combobox is still is smaller, then in the dropdown-list.
I also set a bold fontface for dropdown-list, but the text in the combobox doesn't appear in bold.
Could you help to fix it?

Thanx,
Daniel


I fixed it. Simpli calling setFont() on a ExComboBox instance did it. The renderer has affect on the items in the Dropdown-list but not on the text in the Combobox.
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 21 guests