Following is attached the code to create a list box containing check box in it.using on gwt components and gwt-ext(version 0.9.3) components:~
Just copy this code and make the classes :~
/**
* @(#) CommonFilterGridWitChkBx.java
* @version 1.0 24Mar2008
*/
package com.client;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* It is used to create List with Check box components present
*/
public class CommonFilterGridWitChkBx
{
private CheckBox cbAth[] = null;
private ScrollPanel checkboxScrollPanel = null;
/**
* Constructor is used to create Vertical Panel with multiple check boxes
* inside it.
*
* @param valueCriteria HashMap Containing the value to be made as checkbox
* @param width String width of the panel
* @param height String height of the panel
* @param scrlPnlWid String width of the scrollPanel
* @param scrlPnlHt String height of the scrollPanel
*/
CommonFilterGridWitChkBx(HashMap valueCriteria,
String width,
String height,
String scrlPnlWid,
String scrlPnlHt
)
{
cbAth = new CheckBox[valueCriteria.size()];
VerticalPanel vpForChkBx = new VerticalPanel();
vpForChkBx.setSize(width, height);
// Map map = valueCriteria;
ArrayList alKey = new ArrayList(valueCriteria.keySet());
Collections.sort(alKey);
Iterator itr = alKey.iterator();
int i = 0;
while (itr.hasNext())
{
String key = (String) itr.next();
String lbl = (String) valueCriteria.get(key);
cbAth[i] = new CheckBox(lbl);
cbAth[i].setTitle(key.toString().trim());
vpForChkBx.add(cbAth[i]);
i++;
}
vpForChkBx.setStyleName("gridBackground");
checkboxScrollPanel = new ScrollPanel();
checkboxScrollPanel.add(vpForChkBx);
checkboxScrollPanel.setSize(scrlPnlWid, scrlPnlHt);
}
/**
* Returns the check box panel
*
* @return Panel containing all the chechBoxes
*/
public ScrollPanel getCheckboxPanel()
{
return checkboxScrollPanel;
}
}
Then copy the following code in onmodule load class:~
package com.client;
import java.util.HashMap;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.gwtext.client.util.DOMUtil;
import com.gwtext.client.widgets.form.Form;
import com.gwtext.client.widgets.form.FormConfig;
/**
* Entry point classes define onModuleLoad()
.
*/
public class MyRPCTest implements EntryPoint {
public void onModuleLoad() {
Form frm = new Form("Form", new FormConfig() {
{
setWidth("200px");
setLabelWidth(20);
setSurroundWithBox(true);
}
});
frm.fieldset("ListBox");
frm.container("listbox");
frm.end();
frm.end();
HashMap hm = new HashMap();
hm.put("Apple", "Apple");
hm.put("Banana", "Banana");
hm.put("Peach", "Peach");
hm.put("Cherry", "Cherry");
hm.put("Mango", "Mango");
hm.put("Lichi", "Lichi");
CommonFilterGridWitChkBx chkBxInLst = new CommonFilterGridWitChkBx(hm,"100px","100px","130px","80px");
ScrollPanel scrlPnl = chkBxInLst.getCheckboxPanel();
frm.render();
Panel pnlLstChkBx = DOMUtil.convertDivToPanel("listbox");
pnlLstChkBx.add(scrlPnl);
RootPanel.get().add(frm);
}
}
This will create the list box containing the items as a checkbox within the list box to give it more closer look as list box include this following css in ext-all.css file
.gridBackground{
background-color:white;border:1px solid #B5B8C8;
}
CODE TO Create ListBox with checkbox using gwt and gwtext0.9.3
Labels: GWT
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment