setSelectedValue and requestFocusInWidow

I am trying to programmatically set the Selected Focus Border around a particular item in a list box. Here is my script.

list1 = event.source.parent.getComponent('MenuContainer1').getComponent('list') print list1 #list1.setSelectedValue('Overview') #list1.requestFocusInWindow()

The print result is ‘none’.
If I enable either of the list1.doSomething functions, I get the expected error stating that

AttributeError: 'None' object has no attribute 'doSomething'

What am I missing here?

Your list1 is null - you’re net getting the list correctly. Either you have one of those names wrong (“MenuContainer1” or “list”) (they’re case sensitive), or you’re going in at the wrong level of the tree…

Should be easy to fix - print out the results of intermediate stages of that first line.

The easy way of getting to that property in the Jython editor is with the Insert Property Reference button, which looks like a chain link. It will let you browse down to the Selected Focus Border property of your list box directly. Then use the (=) assignment operator to set the border type.

How do you define borders in Jython? It expects javax.swing.border.Border, but I think there’s a simple string encoding to set the border type.

Hes not actually setting a focus border, he’s requesting focus for the component so that his focus border shows up. But the insert property reference button is still a good tip - at least it’ll get you to the component properly.

Case sensitive. Doh!

So now the script seems to run fine, and the value prints correctly, but the focus box does not show up.

Here’s my script.

[code]list1 = event.source.parent.getComponent(‘MenuContainer1’).getComponent(‘List’)
#print list1

value = list1.getSelectedValue()
event.source.SelectedValue = value #results->a property, displayed

print value


You actually need to call “requestFocusInWindow” on a subcomponent of the list proper - like this (see the last line):

[code]list1 = event.source.parent.getComponent(‘MenuContainer1’).getComponent(‘List’)
#print list1

value = list1.getSelectedValue()
event.source.SelectedValue = value #results->a property, displayed

print value


Note that these hoops you’re jumping through could have been avoided by using the Selected Background color to indicate selection, instead of the focus border.

Hope this helps,

Selected Background is good. Thanks. However, I’m stuck on another piece of the problem.

I have a series of list boxes acting as menus. Each list contains a menu subset and each is identified by a dynamic property string ‘menuGroup’. The ‘Selected Background’ color for each box is changed based on whether its ‘menuGroup’ string matches a tag value. This works great.

The user navigates around (zooms in or out of levels of data detail). When they return to a previous zoom level, they return to the menu choice where they were when they left that level. That also works.

However, I need to be able to highlight the appropriate menu item to indicate where they returned to. They have not actively selected that menu item - they just selected the new zoom level.

For trial, I have this script on a button.

[code]list1 = event.source.parent.getComponent(menuNum).getComponent(‘List’)

label = fpmi.tag.getTagValue(’[Client]CurrentMenuItemLabel’)

‘menuNum’ is a previously defined string. The tag hold a string which is the last chosen item in the list box, at he zoom level they are returning to.

This works great on the test button, which is on the same screen as the menu lists. The problem is that the navigation button (the zoom button) is on a different screen from the menu list boxes. It seems that there is no event to reference.

Does this all make sense? Is there a way to get this done?

Thanks for any guidance.

For an event on one screen to reference components on another screen, you need to get the handle for that screen first, like this:

menuWindow = fpmi.gui.getWindow("MenuWindow") rootContainer = menuWindow.rootContainer rootContainer.getComponent(...)

Perfect. Almost.

The script on the button writes a few tags, then does a ‘swapto’ a new screen, then does this menu highlighting thing (which is encapsulated in a script module). Everything works well, except that it doesn’t highlight the menu item until I press the button a second time. When I press it a second time, it works correctly to highlight the menu item.

Any thoughts?

A bit more info.

If I print the return value of setSelectedValue(), I get ‘none’.

value = list1.setSelectedValue(label) print value

If there are identical values in the menu list at each zoom level, I get a highlight, which shows up at the position in the menu I am leaving. In fact, if I watch I can see the highlight appear, then the list values refresh.

It seems that I am having a race, as the menu boxes refresh their content via a SQL query based on the content of the tags that are written. The setSelectedValue() command is after the tags are all written, at least in the order of commands in the script, but presumably the query takes some time.

I tried refreshing the dataset for each menu box from within the zoom button script, before either swapTo() or setSelectedValue(). Seems like that might work, but setSelectedValue() still returns ‘none’ and the highlighting still misbehaves the same way.


Yeah, when you set properties that affect a bound SQL query, that query will execute some time later. Any calls to setValue() within that same script will almost certainly fail. You need to delay the setValue by wrapping it in a fpmi.system.invokeLater, maybe giving it 50ms or so.