组件Link为超链接。指向一个外部资源。 Link实际为一HTML 链接<a href>。和Button 不同的是,Link 不会在服务器端触发一个事件。你也可以使用setIcon 为Link添加一个图标:
- // Textual link
- Link link = new Link("Click Me!",
- new ExternalResource("http://vaadin.com/"));
- ...
- // Image link
- Link iconic = new Link(null,
- new ExternalResource("http://vaadin.com/"));
- iconic.setIcon(new ThemeResource("img/nicubunu_Chain.png"));
- // Image + caption
- Link combo = new Link("To appease both literal and visual",
- new ExternalResource("http://vaadin.com/"));
- combo.setIcon(new ThemeResource("img/nicubunu_Chain.png"));
上面代码显示结果如下:打开超链接时可以支持超链接打开的目标模式(Target),可以通过setTargetName 来指定,比如 _blank 在新窗口中显示超链接。 此外,可以通过setTargetWidth, setTargetHeight, setTargetBorder 指定显示窗口的大小和边框。如下面代码:
- // Open the URL in a popup
- link.setTargetName("_blank");
- link.setTargetBorder(Link.TARGET_BORDER_NONE);
- link.setTargetHeight(300);
- link.setTargetWidth(400);
除Link组件之外,Vaadin也可以通过Button (使用Reindeer.BUTTON_LINK风格)来定义一个超链接,也可以使用XHTML 模式使用Label来显示一个超链接。