I have put a question(with my answer) and one of active participant gave a brilliant answer ,here is that link: SelectBox.
I have tried,and here is the link : My Question
The answer will be more better if
By Default value of Apple and Cat(which will be selected all time) will be shown in the textbox.
Selecting any check box (except:start & stopall, whether it is single or double or triple),the corresponding checkboxes value should have to shown in the textbox,like Apple, or BallElephant or CatDogElephant.
either startall or stopall will be selected at a time.
any inputs will be appreciated.
There is the Chosen jquery plugin that looks like what you want.
Otherwise, you can make yout input field readonly and update its values with a js function when a checkbox is clicked.
Related
I have a table of forms which accepts first name, last name etc. When I navigate through using the tab key and enter some text in first name, all of the text disappears and that row gets selected. I have tried almost all techniques.
Is there any way we can avoid that using coding?
If I use the mouse then it wont give that error.
Assuming an otherwise correct use of JTable, you may need to terminate the edit when focus is lost, as suggested here and here:
table.putClientProperty("terminateEditOnFocusLost", true);
I'm using
int TxtAge = Integer.parseInt(tfAge.getText().trim());
to get value from my textfield and search it in database.
Then, I'm using Integer age = Integer.parseInt(stringTokenizer.nextElement().toString()); to go to next attributes in my database.
I have no problem using those codes for textfield but when I'm using the JComboBox the result won't display. How to use the StringTokenizer.nextElement() for JComboBox? Is is the same with TextField?
String sex=(String) stringTokenizer.nextElement();
I tried this code but still failed :(
You seem to have left out the relevant portions of your code, i.e. how you are handling setting/getting items in the JComboBox. Whether you read these values from a database, a file or have them hardcoded is irrelevant to the question.
Since you do ask whether it is the same as with a JTextField, I can at least answer this; it is not the same. The question indicates that you're quite new to Swing. You would probably benefit from working through a basic Swing tutorial, just to get a grip on how to work with these basic GUI elements. For JComboBox, check out Oracles own How to Use Combo Boxes.
Anyways, when working with JComboBox, you will need to first populate it with the values that users can choose from and set the currently selected value. Retrieving the currently selected value is just a simple method call.
Further, you have the possibility of making a combobox editable. This means that the user can edit the text in the combo box to something that was not pre-populated. By default, this option is turned off.
I'll provide some examples.
Initialize:
JComboBox sexComboBox = new JComboBox();
sexComboBox.addItem("Not selected");
sexComboBox.addItem("Male");
sexComboBox.addItem("Female");
sexComboBox.addItem("Do not want to disclose");
By default, the first item you added is selected. To select another one, you need to add one of the following lines:
sexComboBox.setSelectedIndex(1); // zero-based index, "Male" is selected item
sexComboBox.setSelectedItem("Female"); // sets the selected item to "Female"
To enable user to edit the contents to something that was not pre-defined, just add the line:
sexComboBox.setEditable(true);
To retrieve the currently selected value:
String selectedItem = (String) sexComboBox.getSelectedItem();
i have a friend list from facebook and above the list ,there is edit text box.
i able to retrieve the name from the list .
When i click on the one position from the list ,i want to show that name to the edit text,then if other name is selected ,then it added to the edit text box after first selected name and so on.
I had tried finding the way of doing this ,but could not able to get the proper answer for implementing this .
added the name to the list which is being selected by the user.
for example
below is the list and above is the edit text when i click on the list view position,the
value of that particular position to be shown in the edit text,now if other position is
clicked by the user ,in the edit text ,it will be shown as name1,name2.
if third value is selected from the list then i should be shown as name1,name2,name3
and so on.
When i am trying to add in the array list,on clicking ,it overwrite the previous value and shown only one value in the edit text.
Regards
inder
Look here, this is a beautiful solution for you to use in your code
I'm new to GWT. I have a simple SuggestBox which is populated using a MultiWordSuggestOracle. Users input their data to this SuggestBox, and if they find any match with the existing Suggestions its well and good. I'm able to retrieve this value in the SelectionHandler code as below.
display.getSuggestBox().addSelectionHandler(new SelectionHandler<Suggestion>() {
public void onSelection(SelectionEvent<Suggestion> event) {
String selectedProperty = ((SuggestBox)event.getSource()).getValue();
// do something with the property value
}
});
But users are allowed to enter values which are not already in the Suggestion oracle, in which case I should read this value and do something with this,may be saving to db as a new data.(The thing which I'm looking for is something like a browsers navigation widget where we show suggestions, users can pick up any suggestion or he can type in his new entry and carry on.) What I needed is a way to retrieve this new text user has entered? Data will be read on a button click. What I tried out is this.
display.getSaveBtn().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String selectedProperty = display.getSuggestBox().getValue();
//String selectedProperty2 = display.getSuggestBox().getText();
// Blank in both cases :(
// tried display.getSuggestBox().getTextBox().getValue(),but blank again
}
});
I tried to employ onChange() event handlers (as shown below)
display.getSuggestBox().addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
String selectedProperty = ((SuggestBox)event.getSource()).getValue();
Window.alert("on change -- "+selectedProperty);
}
});
This is working fine except one scenario. Suppose there are two suggestions in the oracle,say 'createTicketWsdl' and 'createTicketTimeout'. When the user types in 'cr', he is opted with these two options, and if he selects 'createTicketWsdl' by pressing keyboard ENTER, then my alert is printing 'createTicketWsdl' which is correct. But if he selects 'createTicketWsdl' using mouse, then my alert is printing 'cr' (I tried to post the screenshot to give a better understanding, but being a new user I'm not allowed).(which I wanted to get as 'createTicketWsdl'since thats what he has selected). Soon after printing my alert, the value in the SuggestBox changes to 'createTicketWsdl'.
Is there a way to retrieve the value of the suggest box? I saw a similiar thread GWT SuggestBox + ListBox Widget, where some source code for a custom widget is available. But I didn't take the pain of trying out that, since what I want is simply get the current value from the SuggestBox and I hope there should be some easy way.
Thanks for all your help!
Your question is not very clear. You need to clarify your language a lil' bit. For example - is the following a question or an assertion? I mean, it sounds like an assertion but it has a question mark.
What I needed is a way to retrieve this new text user has entered?
Also, I do not understand what you mean by "he is opted by". Did you mean to say, "he is presented with the options ..." ?
Therefore, I am guessing your situation.
You have a listbox of existing items.
You have a textbox which allows freeform text entry
Any items whose prefix values matches the current textbox entry, the listbox items would be filtered to be limited to the matching items.
Even if the current textbox entry presents matching prefixes to filtering the listbox, the user can still perform freeform text entry. So, there are two possible cases here
4.1 the user clicks on the list box to select one of the filtered items
4.2 the user press enter key, which triggers selection of the current value of the textbox.
However, you find your widget participating in a race condition, so that when you click on the widget, the ValueChangeHandler gets triggered rather than the SelectionHandler. I do not know the structure of your widget so that is my best guess.
The problem is that you are allowing two separate modes of obtaining an outcome and you probably did not have well-defined state machine to handle choosing the appropriate mode. One mode is by the textbox and the other is by selection on the listbox - and you do not have a well-defined way of which would mode would be effective at any moment.
If my guess is accurate, this is what you need to do:
You must restrict your outcome to coming from only the textbox.
Your listbox selection must not trigger any outcome. Any change in listbox selection must propagate back to the textbox - to allow the user the chance of making further freeform entry based on that value.
only the keyboard enter on the textbox will trigger the final outcome.
I have two fields in a webpage. Both are composite primary keys. Out of that when I select one field (eg. out of a list of countries I select - India), the second field should display all the values corresponding to the previous field (eg. after selecting India I should get all the states in another drop-down menu).
I'm implementing this using JSP and Ajax.
Can someone please help me with this or send me the code snippets.?
Neal,
There are various codes available like this. Just do googling.
Try with link