private void addNullLabelExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "How to use accessible null WLabels" ) ) ; add ( new ExplanatoryText ( "These examples shows how sometime a null WLabel is the right thing to do." + "\n This example uses a WFieldSet as the labelled component and it has its own \"label\"." ) ) ; // We want to add a WFieldSet to a WFieldLayout but without an extra label. WFieldLayout fieldsFlat = new WFieldLayout ( ) ; fieldsFlat . setMargin ( new Margin ( null , null , Size . XL , null ) ) ; add ( fieldsFlat ) ; WFieldSet fs = new WFieldSet ( "Do you like Bananas?" ) ; fieldsFlat . addField ( ( WLabel ) null , fs ) ; // now add the WRadioButtons to the WFieldSet using an inner WFieldLayout WFieldLayout innerLayout = new WFieldLayout ( WFieldLayout . LAYOUT_STACKED ) ; // The content will be a group of WRadioButtons RadioButtonGroup group1 = new RadioButtonGroup ( ) ; WRadioButton rb1 = group1 . addRadioButton ( 1 ) ; WRadioButton rb2 = group1 . addRadioButton ( 2 ) ; //make the labels for the radio buttons WLabel rb1Label = new WLabel ( "" , rb1 ) ; WImage labelImage = new WImage ( "/image/success.png" , "I still like bananas" ) ; labelImage . setHtmlClass ( "wc-valign-bottom" ) ; rb1Label . add ( labelImage ) ; WLabel rb2Label = new WLabel ( "" , rb2 ) ; labelImage = new WImage ( "/image/error.png" , "I still dislike bananas" ) ; labelImage . setHtmlClass ( "wc-valign-bottom" ) ; rb2Label . add ( labelImage ) ; innerLayout . addField ( rb1Label , rb1 ) ; innerLayout . addField ( rb2Label , rb2 ) ; // add the content to the WFieldLayout - the order really doesn't matter. fs . add ( group1 ) ; fs . add ( innerLayout ) ; }
Example of when and how to use a null WLabel .