由于FloatingActionButton is inactive above a TextArea or TextField whilst editing我尝试通过将TextField和FloatingActionButton放入一个样式为TextField的Container来解决此问题。但这以一种非常奇怪的方式展示 - 请参阅以下示例中的第二个TextField:
public class FormSeveralInputFields extends Form {
public FormSeveralInputFields() {
super("FormSeveralInputFields", new BoxLayout(BoxLayout.Y_AXIS));
setScrollableX(false);
setScrollableY(true);
Container containerFields = new Container(new GridBagLayout());
Style styleContainerFields = containerFields.getAllStyles();
styleContainerFields.setPadding(1, 1, 1, 1);
styleContainerFields.setPaddingUnit(
Style.UNIT_TYPE_SCREEN_PERCENTAGE,
Style.UNIT_TYPE_SCREEN_PERCENTAGE,
Style.UNIT_TYPE_SCREEN_PERCENTAGE,
Style.UNIT_TYPE_SCREEN_PERCENTAGE);
getContentPane().add(containerFields);
int x = 0, y = 0;
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
gbc.gridy = y;
containerFields.add(gbc, new Label("TextField1"));
}
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = ++x;
gbc.gridy = y;
TextField textField = new TextField(10);
Log.p(textField.getStyle().getBorder().getClass().getSimpleName());
FloatingActionButton.setIconDefaultSize(2.0f);
FloatingActionButton floatingActionButton = FloatingActionButton.createFAB(FontImage.MATERIAL_CLEAR);
Container container = floatingActionButton.bindFabToContainer(textField, Component.RIGHT, Component.CENTER);
floatingActionButton.addActionListener((aActionEvent) -> textField.setText(""));
containerFields.add(gbc, container);
}
x = 0;
y++;
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
gbc.gridy = y;
containerFields.add(gbc, new Label("TextField1"));
}
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = ++x;
gbc.gridy = y;
TextField textField = new TextField(10);
FloatingActionButton.setIconDefaultSize(2.0f);
FloatingActionButton floatingActionButton = FloatingActionButton.createFAB(FontImage.MATERIAL_CLEAR);
floatingActionButton.addActionListener((aActionEvent) -> textField.setText(""));
BorderLayout borderLayout = new BorderLayout();
Container container = new Container(borderLayout);
container.setUIID(textField.getUIID());
textField.setUIID("");
container.add(BorderLayout.CENTER, textField);
container.add(BorderLayout.EAST, floatingActionButton);
containerFields.add(gbc, container);
}
}
}
答案 0 :(得分:0)
我们最近添加了ClearableTextField
来提供这种功能:
TextField tf = ...;
myContainer.add(ClearableTextField.wrap(tf));