简体   繁体   English

Apache Pivot:获取按钮(togglebutton)状态

[英]Apache pivot : Getting button (togglebutton) state

my name is Javier, from Spain 我叫哈维尔,来自西班牙

At first, apologize for my inexperience, and for my english :) 首先,为我的经验不足和英语致歉:)

This is question anyway: 无论如何这是一个问题:

I'm looking for getting a button state in Apache Pivot. 我正在寻找Apache Pivot中的按钮状态。 I've tried with many listeners, without result. 我尝试了许多听众,但没有结果。 I don't find any property as "state", "value" or similar. 我找不到“状态”,“值”或类似属性。

The closest thing I've found is: 我发现的最接近的是:

    //Intercepta los eventos de toggleButton
    BotonGenerico.getButtonStateListeners() .add(new ButtonStateListener() {                  

        @Override
        public void stateChanged(Button button, State previousState) {
            System.out.println("Changed!");
        }
    });

But doesn't seem working. 但似乎没有用。

Thanks 谢谢

I'm going to answer myself, after researching the issue, if anyone is interested: 研究问题后,如果有人有兴趣,我将回答自己:

In Apache Pivot there is no control called "toggle button" as such. 在Apache Pivot中,没有所谓的“切换按钮”控件。 Instead of this, i can use the control called "button". 代替此,我可以使用称为“按钮”的控件。

In my case, "BotonGenerico" can transformed in ToggleButton, only changing the toggleButton property via setToggleButton: 就我而言,“ BotonGenerico”可以在ToggleButton中进行转换,只需通过setToggleButton更改toggleButton属性即可:

BotonGenerico.setToggleButton(true); 

After this, I can view or change it state, via getState and setState: 之后,我可以通过getState和setState查看或更改其状态:

BotonGenerico.setState(State.SELECTED);
BotonGenerico.getState(); 
//State can be State.SELECTED, State.UNSELECTED or State.MIXED

On many cases, we have to work with 'components', instead 'pushbuttons' (pe in some events as mouseMove, mouseOut. focusedChanged...). 在许多情况下,我们必须使用“组件”,而不是“按钮”(在某些情况下为pe,例如mouseMove,mouseOut,focusedChanged ...)。 Casting that mentioned 'component' to button, is simply to manipulate. 将提到的“组件”投射到按钮上只是为了操作。

Sample: 样品:

//Changes PushButton background color when focus changed
@Override
public void focusedChanged(Component component, Component obverseComponent) {
//casting component and obverseComponent in order to convert it in PushButtons
PushButton botonComponent=(PushButton) component;
PushButton botonObverseComponent=(PushButton) obverseComponent;

    if (botonComponent.isToggleButton()) {                        
        if (botonComponent.getState() != State.SELECTED) {
            System.out.println("Selected");
            botonComponent.getStyles().put("backgroundColor", #000000);
        }
    }
}

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM