Universal Robots Forum

Select elements toString() Capitalization bug


I’ve tried to make a unit conversion library using enums, here’s a screenshot

I’ve tried adding the elements of this enum to a SelectDropDownList in 2 different ways, one by one with a forloop and using the setItems() function.
Either way I got the same result:

Looking at this image it is clear that the overriden toString() function is used when the element is displayed in the dropdown, however, for some unknown reason the return value gets capitalized.
Units like ‘m’ and ‘mm’ would look very confusing capitalized like this: ‘M’, ‘Mm’ which makes this method unusable, but if this tiny bug got fixed, this would be the most fool proof way of unit conversion on the UI.

Thank you!

I cannot seem to re-create your bug.
Check out the “Wrap Script” sample in the Samples topic.
This lists the found .script files in the programs folder, and shows them in the drop-down without capitalization.

What is different in your code from this sample?

Basically, I create the file name array like this:

File dir = new File(directory);
File[] files = dir.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
       return name.toLowerCase().endsWith(".script");

(Note the “toLowerCase” does not affect the name added to the dropdown, it is only used as boolean check to see if the file ends with .script)

The files are added to the drop down like this:

for(int i = 0; i < files.length; i++){

Thank you for your reply!

As far as I can tell in the code you’ve included, the items being added to the Selector are Strings. In my case I was trying to add Enum elements, not Strings. That’s when the above mentioned bug happens.
If I add Strings everything works fine, however that means that when a select happens, I have to parse that value (either using the index or the string value) and convert it back to an Enum element. I was hoping that by adding the elements directly to the selector, I wouldn’t have to convert it back, which would make the app more foolproof.