【问题标题】:Vaadin 8. Resource cannot be resolvedVaadin 8. 资源无法解析
【发布时间】:2017-10-12 07:56:24
【问题描述】:

我尝试添加一个覆盖插件。 https://vaadin.com/directory/component/overlays 我有图像叠加的问题。我得到了那个错误:

The type com.vaadin.terminal.Resource cannot be resolved. 
It is indirectly referenced from required .class file

问题出在这一行:

io.setImage(res);

我该如何解决?我将 icon-new.png 放入类包文件夹并添加到 maven overlays 插件中

我的代码:

final ImageOverlay io = new ImageOverlay(button);

Resource res = new ClassResource(this.getClass(), "../icon-new.png");

io.setImage(res);
io.setComponentAnchor(Alignment.TOP_LEFT); // Top left of the button
io.setOverlayAnchor(Alignment.MIDDLE_CENTER); // Center of the image
io.setClickListener(new OverlayClickListener() {
public void overlayClicked(CustomClickableOverlay overlay) {
            Notification.show("ImageOverlay Clicked!");
        }
 });
 layout.addComponent(io);
 io.setEnabled(true);

我需要在按钮上显示一个叠加层。如果用户单击此按钮并添加新内容,则按钮上会显示类似 taht 的内容

【问题讨论】:

    标签: java vaadin vaadin8 vaadin4spring


    【解决方案1】:

    这是因为它仅与 Vaadin 6 兼容,正如附加页面中所指出的那样:

    如果您滚动到 cmets 部分,有人建议使用与 Vaadin 7 兼容的附加组件的分支,但我看不到与 8 相关的任何内容:

    大家好!您可以在这里找到 Vaadin 7.6 的 1.1.3 版本:https://github.com/Haulmont/vaadin-overlays/releases

    尤里·阿尔塔莫诺夫

    与多个 Vaadin 版本兼容的附加组件明确指出这一点,并且通常(但不一定...开发人员的选择)具有不同的版本编号,例如:1.x 用于 Vaadin 6,2.x 用于 Vaadin 7 , Vaadin 8 的 3.x 等:

    无论哪种方式,单击特定 Vaadin 版本的链接,将选择与其兼容的最新插件版本。或者,如果您从下拉列表中选择附加版本,与之兼容的 Vaadin 版本将相应更新。


    更新后编辑

    您可以使用常规按钮 + 预定义的 BUTTON_ICON_ALIGN_RIGHT Valo 样式。来自 javadoc:

    /**
     * Align the icon to the right side of the button caption. Can be combined
     * with any other Button style.
     */
    public static final String BUTTON_ICON_ALIGN_RIGHT = "icon-align-right";
    

    请注意,为了获得最佳 UI 效果,我使用了 24x24 图标,但根据您的要求,您可以根据需要调整主题大小。此外,如果您没有图标并且不想花钱或花费时间购买或创建自己的图标,您可以使用现有的Vaadin Font Iconslist of iconsmatching java enum

    public class ButtonWithIconOnTheRightComponent extends VerticalLayout {
        public ButtonWithIconOnTheRightComponent() {
            // text filed to specify icon URL
            TextField urlField = new TextField("Icon URL", "http://files.softicons.com/download/toolbar-icons/status-icons-set-by-iconleak/png/16x16/30.png");
    
            // button which updates its icon using the URL specified in the text field above
            Button button = new Button("Update icon", event -> event.getButton().setIcon(new ExternalResource(urlField.getValue())));
    
            // use valo style to align icon to the right
            button.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_RIGHT);
    
            // add components to the UI
            addComponents(urlField, button);
            setSpacing(true);
        }
    }
    

    【讨论】:

    • 感谢您的帮助。您还知道其他类似的 vaadin 解决方案吗?
    • @AnnaK 如果您可以描述您的用例,也许我们可以使用标准 Valo 样式找到一些替代方案或解决方法。
    • 谢谢 :) 我更新了我的问题并发送了我想要达到的图像!
    • @AnnaK 使用常规按钮和预定义的 Valo 样式查看底部更新,无需任何附加组件。
    • 看起来不错,谢谢。但是如果我再次单击按钮中的图标,我需要单击的东西我没有图标
    猜你喜欢
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多