This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes GWT and the fly likes set primaryStyleName and css Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "set primaryStyleName and css" Watch "set primaryStyleName and css" New topic
Author

set primaryStyleName and css

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
when create project, the css file already contains some predefined css class like
.gwt_VerticalSplitPanel .splitter{
......
}

but is it necessary to explicit call the

when create a VerticalSplitPanel?

I have this doubt because I found sometimes even the widget (e.g. treee, treeitem) has not explicit call setStylePrimaryName, it can still automatically refer to the corresponding css class in css file,
but some cannot (like gwt-HorizontalPanel).
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10270
    
    8

These components call the setStyleName("styleName") when they are initialized. You do not need to make explicit calls yourself.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
Maneesh Godbole wrote:These components call the setStyleName("styleName") when they are initialized. You do not need to make explicit calls yourself.


I found it quite confusing.
when new a gwt project, the default css file has some style class for some component but not all.
for example, TabBar has corresponding css class in css file as follow:


but some component like DockPanel has no default css class in the css file.
if I add the style class in css as follow:


and then write the following code:


I found the following result

tabBar1.getStylePrimaryName() = gwt-TabBar
dockPanel1 primaryStyleName =
dockPanel1 primaryStyleName = gwt-DockPanel


that is, if the css file default has that classname, then when create the widget, the component will automatically set their stylePrimaryName corresponding to the css file,
but if the widget has no default css style class in css file and we add it manually, then even using their naming convention "gwt-"+ WidgetName, the widget still cannot automatically set
their stylePrimaryName.

is it normal behavior of gwt?
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
Not all widgets use primary styles, in particular many panel types. For HorizontalPanel, there is nothing that would need to be set for its style for general use. And it wouldn't necessarily be good for Google to have set a primary style, since the same class might be used multiple times within an app for totally different purposes. BTW, the Javadocs usually list the styles used by a widget (but unfortunately, not always). But, if there is no rule in the CSS, then GWT isn't going to bother setting a primary style.

If you want a primary style for a DockPanel, you can either manually set it for each instance, as you did, or extend DockPanel with a new class that sets its own primary style with its own name.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240

or extend DockPanel with a new class that sets its own primary style with its own name.


Possible to set primary stlye with class?
 
Consider Paul's rocket mass heater.
 
subject: set primaryStyleName and css