You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gwt-styling.asciidoc 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. title: Styling a Widget
  3. order: 8
  4. layout: page
  5. ---
  6. [[gwt.styling]]
  7. = Styling a Widget
  8. To make your widget look stylish, you need to style it. There are two basic ways
  9. to define CSS styles for a component: in the widget sources and in a theme. A
  10. default style should be defined in the widget sources, and different themes can
  11. then modify the style.
  12. [[gwt.styling.class]]
  13. == Determining the CSS Class
  14. The CSS class of a widget element is normally defined in the widget class and
  15. set with [methodname]#setStyleName()#. A widget should set the styles for its
  16. sub-elements as it desires.
  17. For example, you could style a composite widget with an overall style and with
  18. separate styles for the sub-widgets as follows:
  19. [source, java]
  20. ----
  21. public class MyPickerWidget extends ComplexPanel {
  22. public static final String CLASSNAME = "mypicker";
  23. private final TextBox textBox = new TextBox();
  24. private final PushButton button = new PushButton("...");
  25. public MyPickerWidget() {
  26. setElement(Document.get().createDivElement());
  27. setStylePrimaryName(CLASSNAME);
  28. textBox.setStylePrimaryName(CLASSNAME + "-field");
  29. button.setStylePrimaryName(CLASSNAME + "-button");
  30. add(textBox, getElement());
  31. add(button, getElement());
  32. button.addClickHandler(new ClickHandler() {
  33. public void onClick(ClickEvent event) {
  34. Window.alert("Calendar picker not yet supported!");
  35. }
  36. });
  37. }
  38. }
  39. ----
  40. In addition, all Vaadin components get the [literal]#++v-widget++# class. If it
  41. extends an existing Vaadin or GWT widget, it will inherit CSS classes from that
  42. as well.
  43. [[gwt.styling.default]]
  44. == Default Stylesheet
  45. A client-side module, which is normally a widget set, can include stylesheets.
  46. They must be placed under the [filename]#public# folder under the folder of the
  47. widget set, a described in
  48. <<../clientside/clientside-module#clientside.module.stylesheet,"Specifying
  49. a Stylesheet">>.
  50. For example, you could style the widget described above as follows:
  51. ----
  52. .mypicker {
  53. white-space: nowrap;
  54. }
  55. .mypicker-button {
  56. display: inline-block;
  57. border: 1px solid black;
  58. padding: 3px;
  59. width: 15px;
  60. text-align: center;
  61. }
  62. ----
  63. Notice that some size settings may require more complex handling and calculating
  64. the sizes dynamically.