Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 来自动态SWT按钮的ActionEvent_Java_Button_Swt - Fatal编程技术网

Java 来自动态SWT按钮的ActionEvent

Java 来自动态SWT按钮的ActionEvent,java,button,swt,Java,Button,Swt,我正在开发一个从数据库返回结果的UI。我想在返回的每一行旁边放一个按钮。我想根据按钮的状态(真/假)操纵按钮,并根据状态触发几个其他事件。任何帮助都将不胜感激。我的每个按钮都有一个id,但按下时我无法引用它 private ArrayList<ExtButton> btnList = new ArrayList<ExtButton>(); /* * ===================================================

我正在开发一个从数据库返回结果的UI。我想在返回的每一行旁边放一个按钮。我想根据按钮的状态(真/假)操纵按钮,并根据状态触发几个其他事件。任何帮助都将不胜感激。我的每个按钮都有一个id,但按下时我无法引用它

private ArrayList<ExtButton>   btnList        = new ArrayList<ExtButton>();

/*
 * =======================================================
 * Inner Classes
 * =======================================================
 */
class ExtButton extends Composite
{
        private Button button;

        private int m_id;
        public ExtButton(Composite parent, int id) { 
            super(parent, SWT.NULL);
            setLayout(new FillLayout());
            button = new Button(this, SWT.TOGGLE | SWT.FLAT);
            button.setText("MyButton");
            m_id = id;
        }

        public int getId()
        {
            return m_id;
        }

        public Button getButton(){

            return button;
        }
}

...

   private void search(int resultSize)
{
    TableEditor[] rowEditor = new TableEditor[resultSize];

    for (int i = 0; i < resultSize; i++) {
        final TableItem item = new TableItem(resultTable, SWT.NONE);
        rowEditor[i] = new TableEditor(resultTable);
        ExtButton btnSelect = new ExtButton(resultTable, i);

        btnSelect.getButton().setText("Select");
        btnSelect.computeSize(SWT.DEFAULT, resultTable.getItemHeight());

        rowEditor[i].grabHorizontal = true;
        rowEditor[i].minimumHeight = btnSelect.getSize().y;
        rowEditor[i].minimumWidth = btnSelect.getSize().x;

        rowEditor[i].setEditor(btnSelect, item, 0);

        btnList.add(btnSelect);

        btnSelect.getButton().addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent event) {
                    Integer btnId = ((ExtButton) event.getSource()).getParent().getId();
                    ExtButton button = btnList.get(btnId);
                    boolean btnState = ((ExtButton) event.getSource()).getButton().getSelection();
                    if (btnState == true)
                    {

                        button.getButton().setText("Select");
                    }
private ArrayList btnList=new ArrayList();
/*
* =======================================================
*内部类
* =======================================================
*/
类ExtButton扩展了复合
{
私人按钮;
私人国际货币单位id;
公共ExtButton(复合父级,int-id){
super(父级,SWT.NULL);
setLayout(新的FillLayout());
按钮=新按钮(此开关为SWT.TOGGLE | SWT.FLAT);
button.setText(“MyButton”);
m_id=id;
}
公共int getId()
{
返回m_id;
}
公共按钮getButton(){
返回按钮;
}
}
...
私有无效搜索(int resultSize)
{
TableEditor[]行编辑器=新建TableEditor[resultSize];
for(int i=0;i
java:935:错误:找不到符号
[javac]整数btnId=((ExtButton)event.getSource()).getParent().getId();
[javac]^
[javac]符号:方法getId()
[javac]位置:类组合
[javac]1错误


谢谢!

getId
ExtButton
的一种方法,而不是
Composite
(由返回)

getParent()
返回一个没有
getId()方法的
Composite
Integer btnId = ((ExtButton)event.getSource()).getId();