简体   繁体   中英

How can I get my css to work on label GWT Java

I'm playing around with GWT using Netbeans and Java. I have several labels and buttons with css styling which are working, however, I have added another label which I cant seem to get the css to work!

final Label numbersLabel = new Label();

numbersLabel.setStyleName("numberLabel");

drawButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            int numberTest;
            String number;
            numberTest = testRandom.testNumbers();
            number = Integer.toString(numberTest);
            numbersLabel.setText(number);
            RootPanel.get().add(numbersLabel);

        }
    });

Here is the CSS

.numberLabel {
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 28px;
font-weight: bold;
text-align: center; }

On the button click, the label is displayed however, none of the css is implemented. Any help would be appreciated.

You could just go with:

numbersLabel.getElement().getStyle().setProperty("color", "white");

And so on...

But remember to always write the Style Atrribute Name in CamelCase eg font-family = fontFamily

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM