You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Picker组件调用setEnabled(false)后字体样式异常的解决方法求助

Fix for Picker Font Size Change When Disabled in Codename One

Hey, I’ve dealt with this exact quirk in Codename One before! The root cause here is that when you call setEnabled(false) on your Picker, it switches to using its Disabled state style. Since you only configured the unselected, selected, and pressed states for your small UIID in the theme, the Disabled state falls back to the default system disabled font—hence the sudden larger font size.

Here are two solid ways to fix this:

This is the cleanest, most maintainable approach:

  • Open your Codename One Theme Editor
  • Locate the small UIID you created
  • Add a new style configuration for the Disabled state
  • Match the font settings (2.5mm size, same font family) exactly to the other states you’ve already configured
  • Save the theme and rebuild your project. The disabled Picker will now use your custom font instead of the default.

Method 2: Manually Set the Disabled Style in Code

If you prefer to handle it directly in code without editing the theme, you can explicitly set the font for the Disabled style to match your small UIID’s font:

Picker stationPicker = new Picker(); 
stationPicker.setType(Display.PICKER_TYPE_STRINGS); 
stationPicker.setSelectedString("Select the service center"); 
stationPicker.setUIID("small"); 

// Grab the font from your theme's "small" UIID style
Font customSmallFont = UIManager.getInstance().getComponentStyle("small").getFont();
// Apply this font to the Disabled state style
stationPicker.getDisabledStyle().setFont(customSmallFont);

// Your existing style configurations
stationPicker.getAllStyles().setMarginLeft(1); 
stationPicker.getAllStyles().setBgColor(0xcccccc);

// Now disable the Picker—font will stay consistent!
stationPicker.setEnabled(false);

Either approach will ensure the Picker’s font stays at 2.5mm even when disabled, since you’re explicitly defining the style for the Disabled state instead of letting it fall back to defaults.

内容的提问来源于stack exchange,提问作者beck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:08:10