2013-07-24 58 views
5

我想知道在Vaadin 7.0.5中是否有可能在vaadin用戶界面中包含SVG圖形,並且沒有任何附加組件。如何將動態生成的SVG添加到Vaadin UI中?

我目前使用此代碼

StreamResource ressourceSVG = new StreamResource(source, "graphe.svg"); 

Embedded embedded = new Embedded("SVG", ressourceSVG); 
embedded.setType(Embedded.TYPE_OBJECT); 
embedded.setMimeType("images/svg+xml"); 

verticalLayout.addComponent(embedded); 
setContent(verticalLayout); 

有了這個,就什麼也沒有發生......在瀏覽器中的「SVG」文字只是表象。

唯一的topic我在3年前發現這個問題,並沒有在書中找到線索。

在API接口只存在:elemental.svg但它不是真正幫助...

如果你們有任何線索......將是巨大的

+0

會發生什麼?什麼不發生? – nexus

+0

@nexus發生的唯一情況是SVG文本的出現。 在生成的HTML中,我只有這個元素生成的「SVG」文本沒有別的。 – Sidewinder94

+1

如果使用TYPE_IMAGE或TYPE_BROWSER而不是TYPE_OBJECT,會發生什麼情況? – nexus

回答

4

所以,看來答案是,對於一個SVG要在Vaadin 7中顯示,應使用BrowserFrame顯示SVG資源。

使用類似下面的東西,其中sourceSVG是包含SVG數據的streamSource。

StreamResource ressourceSVG = new StreamResource(sourceSVG, "graphe.svg"); 

BrowserFrame embedded = new BrowserFrame("SVG", ressourceSVG); 

verticalLayout.addComponent(component); 
verticalLayout.addComponent(embedded); 
setContent(verticalLayout); 

在載入網頁後重新裝入框架,但它終於摸索

2

事實上,至少在7.1.7版本,你可以直接使用Embedded與SVGs。甚至還有在Book爲例,雖然其與ThemeResource涉及:

// A resource reference to some object 
Resource res = new ThemeResource("img/reindeer.svg"); 

// Display the object 
Embedded object = new Embedded("My SVG", res); 
object.setMimeType("image/svg+xml"); // Unnecessary 
layout.addComponent(object); 

然而,StreamResource S還做工精細,至少在下面的代碼片段:

Embedded image = new Embedded(); 
image.setMimeType("image/svg+xml"); //also unnecessary here :p 
layout.addComponent(image); 
StreamSource source = //define your source 
image.setSource(new StreamResource(source, "image.svg")); 

(注意,如果您需要重新生成你的圖像,你必須提供一個新的,唯一的filename值爲StreamResource

+1

感謝您的提示,我會嘗試記住它,當我將更新我的vaadin應用程序 – Sidewinder94

相關問題