Standard buttons do not have the ability to represent and communicate state, apart from the enabled/disabled state of course. Users often want to be able to turn on/off (toggle) a feature (for example, expand/collapse a tree-like structure) with the push of one button, not two separate buttons for the on/off states, but one button that can visually give cues whether the feature is switched on or switched off. I almost named this recipe "Contextual switching" but realized it would make me sound like medical pros who are often good in saving life but so bad in naming thing (consider osteoporosis), so I thought again.
Contextual switching (well you can't nail me now, after all I've explained it) in GXT
is done with the aid of ToggleButton
, a specialized derivative of button that we can use to demonstrate switching over the expand/collapse feature of ContentPanel
.
/* * We create a content panel and size it. */ final ContentPanel ctPanel = new...