How to set a border on a Vaadin component?

陌路散爱 提交于 2019-12-10 12:53:35

问题


I would like to programmatically set a border around a Form component in Java. How can I do this without having to edit the css style sheet?


回答1:


You could wrap the form with a Panel component, which has a border defined already. Otherwise, not much alternatives than just using CSS.

One option, if you wish to stay inside the server environment, is to use the CSSInject add-on and add the border using that (you still need to write CSS, but you can do it on the server in a Java file and not inside a regular CSS file).




回答2:


Vaadin Flow: Style::set to specify CSS

In Vaddin Flow (Vaadin versions 10 and later), you can conveniently set CSS for a widget or layout programmatically. No need to edit separate CSS files.

  1. On your widget/layout, call getStyle to retrieve the Style object.
  2. On that Style object, call set to pass the name and value of your CSS property.

For example, I find setting a bright colored border on my nested layouts quite helpful for debugging.

myVerticalLayout.getStyle().set( "border" , "6px dotted DarkOrange" ) ; 

You can see this in action with tis screenshot on my Answer to another Vaadin question.



来源:https://stackoverflow.com/questions/5594721/how-to-set-a-border-on-a-vaadin-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!