Spanbutton doesn't delegate properties through event handlers

10 views
Skip to first unread message

howud...@gmail.com

unread,
Nov 9, 2017, 4:03:08 PM11/9/17
to CodenameOne Discussions
The name attribute set on a span button doesn't get propogated through the even handler...see this code:

        SpanButton btnLogin = new SpanButton("Test");
        btnLogin.setName("Test");
    System.out.println(btnLogin.getName() + ":" + btnLogin.toString());
        btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
    Object o = evt.getSource();
    System.out.println(o.toString());
}
        });


results in the following output:
Test:SpanButton[x=0 y=0 width=0 height=0, layout = BorderLayout, scrollableX = false, scrollableY = false, components = [Button, TextArea]]
Button[x=12 y=7 width=0 height=687, text = , gap = 2]


Neither the actual button type nor the name label is propagated through the event.

Shai Almog

unread,
Nov 10, 2017, 12:22:37 AM11/10/17
to CodenameOne Discussions
That's a lead component. Look at the JavaDoc for the action event object.

howud...@gmail.com

unread,
Nov 10, 2017, 2:18:14 PM11/10/17
to CodenameOne Discussions
for those who use forums to help find answers, the correct function call to use is event.getActualComponent(), especially when using lead components
Reply all
Reply to author
Forward
0 new messages