color of apache wicket component
I have the following code:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"
xml:lang="en" lang="en">
<body>
<wicket:panel>
<div wicket:id="serviceListContainer">
<table>
<tr wicket:id="serviceListView">
开发者_如何转开发 <td>
<span wicket:id="service.name"></span>
</td>
<td>
<span wicket:id="service.state"></span> <!-- I WANT TO COLOR THIS PART IN RED! -->
</td>
</tr>
</table>
</div>
</wicket:panel>
</body>
</html>
How can I change the color of the output text that will replace "service.state"? I tried with <font color="red">
but it didn't make any difference.
Thanks!
Other answers have indicated how you can add the style="..."
attribute in the HTML template. If, on the other hand, that you do not wish to do this statically (say, you need to calculate the color and then add it to the component), you should add an AttributeModifier
to the Component1.
Example (untested):
Label l = new Label("service.state", ...);
IModel<String> colorModel = new AbstractReadOnlyModel<String>() {
public String getObject() {
return "color: red;"; // Dummy example
}
}; // Some model, holding a string representation of a CSS style attribute (e.g., "color: ...;") based on some date and/or calculation
l.add(new AttributeModifier("style", true, colorModel);
You could even use a SimpleAttributeModifier
if you don't need the pull-based model:
Label l = new Label("service.state", ...);
String styleAttr = "color: red;";
l.add(new SimpleAttributeModifier("style", styleAttr));
1) Provided that setRenderBodyOnly(true)
has not been called. That would remove the wrapping <span>
element from the output.
From W3Schools:
The <font> tag is deprecated in HTML 4, and removed from HTML5.
The World Wide Web Consortium (W3C) has removed the tag from its recommendations. In HTML 4, style sheets (CSS) should be used to define the layout and display properties for many HTML elements.
Use styles, even if it is inline styling, instead:
<span style="color:red">this is red text</span>
If you're using Wicket you'll want to make sure you're not using setRenderBodyOnly(true)
on the Component with id service.state
, as this would strip the <span>
tag with the style.
<span wicket:id="service.state" style="color:red"></span>
or better is to use proper css classes
精彩评论