如何在vaadin中设置图像数据源

时间:2014-11-28 06:05:43

标签: java user-interface gwt datasource vaadin7

我有一个水平分割面板,我想在其中显示在组合框中选择的图像,但无法为图像文件设置数据源。

FilesystemContainer container = new FilesystemContainer(new File("C:/myData/wallpaper"));
ComboBox box = new ComboBox("Documents", container);


@Override
    protected void init(VaadinRequest request) {
        setContent(box);

        com.vaadin.ui.HorizontalSplitPanel horizontalSplitPanel = new com.vaadin.ui.HorizontalSplitPanel();
        setContent(horizontalSplitPanel);
        horizontalSplitPanel.addComponent(box);
        //horizontalSplitPanel.addComponent(label);
        final Image image = new Image();
        horizontalSplitPanel.addComponent(image);
        box.addValueChangeListener(new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                image.setData(event.getProperty().getValue());
                ///label.set//setPropertyDataSource( (Property) ImageIO.read((ImageInputStream) new TextFileProperty((File) event.getProperty().getValue())));

            }
        });

        box.setImmediate(true);

如何为图像设置数据源。我在Vaadin中很新。

1 个答案:

答案 0 :(得分:1)

我建议这样:

@Override
public void valueChange(ValueChangeEvent event) {
    image.setSource(new FileResource((File)box.getValue()));
}