How can I make GWT list box editable a part from selection
As per my requirement I have written a custom panel which will display three ListBoxes to enable user to select date from this custom list boxes.These three list boxes are responsible for showing month,day,year value. Now I would like to make my three list boxes are editable and at the same time selectable. I mean I would like to provide a user preferences that date can editable and at the same time selectable. How can I do this in GW开发者_Go百科T. Here I am using GWT2.0. Any one please give an idea.
A browser does not provide such a control. Neither does GWT. You will need to code your own. EXT-GWT(not free) ComboBox has this functionality. http://www.extjs.com/examples/ So does Smart GWT (also not free) http://www.smartclient.com/smartgwt/showcase/#styled_combobox_category
If you were to roll your own, you would start with a Composite which has a TextBox and a VerticalPanel that is shown when a TextBox (or part of it) is clicked. Your panel would contain the clickable items.
You could work that out using a suggestBox instead of the list box. But user would have to start typing to display the list.
You can use absolute panel to achive the same ... Below is the code snippet.
Hide the selectbox using textbox adjust the width and location of textbox so that it should cover dropdown list...
final AbsolutePanel absolute_panel_edit_list = new AbsolutePanel();
final TextBox onhold_textbox = new TextBox();
final ListBox onhold = new ListBox();
for (int onholdcount = 0; onholdcount < onHoldTypes.length; onholdcount++)
{
onhold.addItem(onHoldTypes[onholdcount]);
}
onhold.addKeyPressHandler(new KeyPressHandler()
{
@Override
public void onKeyPress(KeyPressEvent event)
{
onhold_textbox.setStyleName("onhold_textbox");
absolute_panel_edit_list.add(onhold,0,8);
absolute_panel_edit_list.add(onhold_textbox,1,10);
absolute_panel_edit_list.setSize("142px", "35px");
flex_row4.removeCell(4, 9);
flex_row4.setWidget(4, 9, absolute_panel_edit_list);
onhold_textbox.addMouseOutHandler(new MouseOutHandler()
{
@Override
public void onMouseOut(MouseOutEvent event)
{
String customized_time = onhold_textbox.getText();
int no_of_elements = onhold.getItemCount();
onhold.addItem(customized_time);
onhold.setSelectedIndex(no_of_elements);
flex_row4.removeCell(4, 9);
flex_row4.setWidget(4, 9, onhold);
flex_row4.setWidget(4, 11, completed_togglebutton);
flex_row4.setWidget(4, 13, completed_label);
}
});
}
});
精彩评论