Skip to main content

problem with tabbed pane's selectedIndex

1 reply [Last post]
tengimon
Offline
Joined: 2008-06-23
Points: 0

Hi,
I am having issue with changing a variable that will help me to keep an index of which tab of tabbed pane has been selected. The example below used to work perfectly on Eclipse(JFX interpreted version) but compiled JavaFX seems like it doesn't support that method.

Here is my code
--------------------------------------------------------------------------------------------
public class myClass{
public attribute x:Integer = 0
on replace {System.out.println("x has changed into "+x)}
}
Frame{
var obj = new myClass
height: 150 width: 300
onClose: function(){System.exit(0);}
visible: true
content:TabbedPane{
tabLayout: TabLayout.WRAP
tabPlacement: TabPlacement.TOP
tabs: [
Tab{title: "tab 1"
content:Label{text: bind "{obj.x}" }
},
Tab{title: "tab 2"
content:Label{text: bind "{obj.x}" }
},
Tab{title: "tab 3"
content:Label{text: bind "{obj.x}" }
},
Tab{title: "tab 4"
content:Label{text: bind "{obj.x}" }
}
]
selectedIndex: bind obj.x

}
------------------------------------------------------------------------------
obj.x is always 0 somehow. I'd like it to change when i select different tabs.

Thanks.

P.S btw, can anybody tell me how to make a function that can send print command to the printer?

Message was edited by: tengimon

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

I guess you are using TabbedPane from the old UI-library, right? In the new library Tabbed Pane is not implemented yet.

I think you are using the bind-expression the wrong way. What you are saying with "selectedIndex: bind obj.x" is, that selectedIndex should be updated whenever obj.x is updated. When I remember correctly binds in the interpreted version where always bidirectional, while in compiled JavaFX they have to be marked bidirectional explicitly.

You either have to revert the bind by defining something like:

[code]
Frame {
var myTabbedPane = TabbedPane {
[...]
}
var obj = MyClass {
x: bind myTabbedPane.selectedIndex
}
content: myTabbedPane
[...]
}
[/code]

or you can simply make the bind bidirectional with

[code]
selectedIndex: bind obj.x with inverse
[/code]