View Full Version : GXT style setting for Fields and ToolItems

6 Jul 2009, 9:18 AM
Hi GXT team,
I am just wondering why you set the styles for ToolItems and Fields in the onRender? the problem with this of course, is it means we are stuck with "xtb-text" and "x-field-text" for example for Label and ToolItems. In my case, I have a quick search bar in my menu bar header (and there is a textfield and a LabelToolItem), and in certain themes (like Slate) the text is black, when I'd like it to be "white" matching the theme. (yes I know I could set the color, but I'd like to do it with styles...)

If I add/remove the style (such as "x-btn-text") this is added, but since the onRender is adding the "xtb-text" first this is getting picked up. Instead of setting this hard-coded, shouldn't it use the setStylePrimaryName( ) in the constructor instead?


6 Jul 2009, 9:21 AM
You can use
item.addStyleName("yourStyle"); that juse overrides the default looking

6 Jul 2009, 9:44 AM
Sven, LabelToolItem.java line: 61 sets the style to the hard-coded style "xtb-text". Thus all calling addStyleName( ) in my code is just adding an additional style. The only other option would be to create a style with a !important, but this would mean I'd have to come up with a style per theme no? This seems like a lot of overhead considering the styles I need are already in the theme.

Here is the src from LabelToolItem:


protectedvoid onRender(Element target, int index) {
setElement(DOM.createDiv(), target, index);
super.onRender(target, index);

Field does something similiar using fieldStyle, which there does not appear to be a way to set on the field object (ie. it is a fixed style "x-form-field"). Part of the reason I switched to LabelToolItem is a felt that Field's having "x-form-field" might be ok, since they are fields afterall, and since my label is not really field related LabelToolItem seemed a better choice.

For reference, here is the code I am using (adding it to a HorizontalPanel):

TableData ltd = new TableData();
LabelToolItem label = new LabelToolItem( StampWebEditor.rbInfo.searchLabel());
add( label, ltd );

9 Jul 2009, 6:28 AM
I didn't see any new activity on this issue since I posted my response to Sven. Can someone confirm that this appears to be a design issue?