是否可以在Vaadin中将描述设置为禁用的文本字段?

时间:2015-05-06 09:15:03

标签: vaadin

我想在禁用的文本字段中添加工具提示。 你有什么想法我该怎么办? 我使用的是Vaadin 6.8.13。 当我在组合框中选择特定项目时,将启用禁用的文本字段。否则,文本字段将被禁用

enter image description here

3 个答案:

答案 0 :(得分:1)

TextField readonly = new TextField("Read-Only");
readonly.setValue("I am sitting here read only");
readonly.setReadOnly(true);
readonly.setDescription("Not this time Mojojojo");

这是你想要的吗?

答案 1 :(得分:0)

当然,为什么它不起作用 - 除非你还没有先尝试过。

通过TextField停用setEnabled(false)并通过setDescription('...')添加说明:

@Grapes([
@Grab('org.vaadin.spring:spring-boot-vaadin:0.0.5.RELEASE'),
@Grab('com.vaadin:vaadin-server:7.4.4'),
@Grab('com.vaadin:vaadin-client-compiled:7.4.4'),
@Grab('com.vaadin:vaadin-themes:7.4.4'),
])
import org.vaadin.spring.annotation.VaadinUI
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.*

@VaadinUI
class MyUI extends UI {
    protected void init(VaadinRequest request) {
        setContent( new TextField().with{
                caption = "I have a Caption"
                value = "And a Value"
                enabled = false
                description = "And have a Description"
                it
        })
    }
}

// spring run vaadin.groovy

答案 2 :(得分:0)

尝试禁用标签,然后将其放入布局中。然后设置该布局的描述。用户不会知道其中的差异。

    VerticalLayout layout = new VerticalLayout();

    TextArea textArea = new TextArea("Hello World");
    textArea.setEnabled(false);

    VerticalLayout textAreaWrapper = new VerticalLayout();
    textAreaWrapper.addComponent(textArea);
    textAreaWrapper.setDescription("Some description");

    layout.addComponent(textAreaWrapper);
    this.setContent(layout);
    this.setSizeFull();

您可以创建自己的类,扩展VerticalLayout并在其中创建TextArea。这样,每次创建“MyTextArea”或任何想要调用它的时候,都不必创建布局包装器。

<强>截图

enter image description here

<强> N.B。

从您的问题我原本以为下面的代码不起作用但它运行正常?我没有在Vaadin 6.8.13中尝试过。我正在使用Vaadin 7.1.2。

    VerticalLayout layout = new VerticalLayout();

    TextArea textArea = new TextArea("Hello World");
    textArea.setEnabled(false);
    textArea.setDescription("Some description");

    layout.addComponent(textArea);
    this.setContent(layout);
    this.setSizeFull();