I have this convertor which is used to get or set label from a combo box:
public class GroupConverter extends StringConverter<ListGroupsObj>
{
@Override
public String toString(ListGroupsObj obj)
{
return obj.getGroupId() + " - " + obj.getGroupName();
}
@Override
public ListGroupsObj fromString(String obj)
{
Scanner fi = new Scanner(obj);
//anything other than alphanumberic characters,
//comma, dot or negative sign is skipped
fi.useDelimiter("[^\\p{Alnum},\\.-]");
while (true)
{
if (fi.hasNextInt()){
//System.out.println("Int: " + fi.nextInt());
return ListGroupsObj.newInstance().groupId(fi.nextInt());
}
break;
}
//TODO when you type for example "45 - NextGroup" you want to take only tyhe number"
return ListGroupsObj.newInstance().groupId(fi.nextInt());
}
}
For example when I type "45 - NextGroup" I would like to get only the number from the value. Can you help me implement this?