【问题标题】:wrap long text of radiobutton in codenameone在代号中包装单选按钮的长文本
【发布时间】:2018-11-29 13:02:51
【问题描述】:

我正在我的应用程序中实现单选按钮,但如果我有单个单选按钮的长文本,它需要自行换行,但目前它显示为单行。代码如下

ButtonGroup buttonGroup = new ButtonGroup();
for (int i = 0; i < (model).getItemCount(); i++)
        {
            String optionLabelStr = (model).getItem(i);
            RadioButton button = new RadioButton(optionLabelStr);
            button.addActionListener(this);
            button.setOppositeSide(false);
            cont.addComponent(button);
            buttonGroup.add(button);
            }

我尝试通过将 UIID 设置为 Spanlabel 来使用 textarea,但是当我选择文本时,它不会标记为单选按钮,但如果我选择单选按钮,它可以正常工作。所以,如果我使用 textarea,我希望即使选择了文本,单选按钮也会被勾选。

对此的任何帮助都会有所帮助。

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    RadioButton 派生自 Button,而 Label 派生自 Label。他们不能包起来。环绕文本是一项复杂的功能,如果我们为所有组件引入它,它会严重影响性能和功能。然而,这很容易通过铅元件实现。事实上SpanButton 是一个领先的组件。

    所以你可以这样做:

    RadioButton button = new RadioButton();
    TextArea textOfButton = new TextArea(optionLabelStr);
    textOfButton.setEditable(false);
    textOfButton.setUIID("RadioButton");
    Container lead = BorderLayout.centerEastWest(button, textOfButton, null);
    lead.setLeadComponent(button);
    button.addActionListener(this);
    buttonGroup.add(button);
    cont.addComponent(lead);    
    

    您在这里有效地做的是用文本包裹按钮。然后使文本看起来像单选按钮的文本。

    最后,您要定义主要组件。这意味着lead 中的所有点击都将转到单选按钮,它将处理所有事件和 UI 状态更改。创建看起来/行为类似于单个按钮的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多