是的,的確如此,在Label
上調用addStyleName
並且按照Morfic的評論通過常數ValoTheme.LABEL_H1
確實有效。
final Label labelPlain = new Label ("This is a plain Label in Vaadin 8.1.0 Alpha 6.");
final Label labelH1 = new Label ("This is a 'h1' Label in Vaadin 8.1.0 Alpha 6.");
labelH1.addStyleName (ValoTheme.LABEL_H1);
下面是一個完整的示例應用程序,在Vaadin 8.1.0阿爾法6.運行示例應用的
package com.example.try_h1;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
/**
* This UI is the application entry point. A UI may either represent a browser window
* (or tab) or some part of a html page where a Vaadin application is embedded.
* <p>
* The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be
* overridden to add component to the user interface and initialize non-component functionality.
*/
@Theme ("mytheme")
public class MyUI extends UI {
@Override
protected void init (VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout ();
final Label labelPlain = new Label ("This is a plain Label in Vaadin 8.1.0 Alpha 6.");
final Label labelH1 = new Label ("This is a 'h1' Label in Vaadin 8.1.0 Alpha 6.");
labelH1.addStyleName (ValoTheme.LABEL_H1);
layout.addComponents (labelPlain, labelH1);
setContent (layout);
}
@WebServlet (urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration (ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
截圖從通常Vaadin archetypevaadin-archetype-application
修改。
![Screenshot of app running, showing a plain Vaadin Label and another Label assigned the style name of constant ValoTheme.LABEL_H1.](https://i.stack.imgur.com/MH3cc.png)
這對我來說很好用v8.0.5。也許你的主題有些腥意? – Morfic
@Morfic你是對的,謝謝。它的確使用我在我的問題中描述的代碼方法。任何有興趣的人都可以在這裏看到我的答案,以獲取完整的示例應用引發我的問題的問題必須是由於我的真實應用程序中的其他問題。 –