天天看点

给Tab增加事件

1,增加双击事件:

给Tab增加事件

tabbedpane_22.addmouselistener(new mouseadapter() {  

            private int heightlevel=0;  

            @override  

            public void mousereleased(mouseevent e) {  

            }  

            public void mousepressed(mouseevent e) {  

            public void mouseclicked(mouseevent e) {  

                jtabbedpane tabbedpane = (jtabbedpane) e.getsource();  

                int selectedindex = tabbedpane.getselectedindex();  

                //当前选择的标签页  

                component selectedtab= tabbedpane.getcomponentat(selectedindex);  

                if(!valuewidget.isnullorempty(selectedtab)&&jsonformattedpane==selectedtab){  

                    if(e.getclickcount()==2){  

                        switch (heightlevel%3) {  

                        case 0:  

                            splitpane_out.setdividerlocation(getdividerheight()[0]);  

                            break;  

                        case 1:  

                            splitpane_out.setdividerlocation(15);  

                        case 2:  

                            splitpane_inner.setdividerlocation(getdividerheight()[0]);  

                            splitpane_out.setdividerlocation(getdividerheight()[1]);  

                            requestpanel.this.repaint();  

                        default:  

                        }  

                        heightlevel++;  

                    }  

                }  

        });  

2,增加右键菜单

给Tab增加事件

tabbedpane_2.addmouselistener(getmouseinputlistener(tabbedpane_2, this));  

 监听器:

给Tab增加事件

public static mouseinputlistener getmouseinputlistener(final jtabbedpane tabbedpane  

            ,final autotestpanel autotestpanel) {  

        return new mouseinputlistener() {  

            public  int count;  

                /*if(e.getclickcount()==1){ 

                    final int rowcount = jtable.getselectedrow(); 

                    final int columncount=jtable.getselectedcolumn(); 

                    int modifiers = e.getmodifiers(); 

                    modifiers -= mouseevent.button3_mask; 

                    modifiers |= mouseevent.focus_event_mask; 

                    mouseevent ne = new mouseevent(e.getcomponent(), e.getid(), 

                            e.getwhen(), modifiers, e.getx(), e.gety(), 

                            2, false); 

//                  processevent(ne); 

                    jtable.editcellat(rowcount, columncount,ne); 

//                  celleditor celleditor=jtable.getcelleditor(rowcount, columncount); 

//                  celleditor.shouldselectcell(ne); 

                    jtable.dispatchevent(ne); 

                }*/  

                system.out.println("mouseclicked"+(count++));  

                processevent(e);  

            /*** 

             * in order to trigger left-click the event 

             */  

                processevent(e);// is necessary!!!  

                system.out.println("mousepressed"+(count++));  

                requestpanel currentrequestpanel2=(requestpanel)tabbedpane.getselectedcomponent();  

                if(valuewidget.isnullorempty(currentrequestpanel2)){  

                    currentrequestpanel2=autotestpanel.getcurrentrequestpanel();  

                if (e.getbutton() == mouseevent.button3) {// right click  

//                  processevent(e);  

                    // system.out.println("row:" + rowcount);  

                    //右键点击表格时,点击的单元格,正常情况返回的是string  

//                  system.out.println("rowcount:"+rowcount);  

//                  system.out.println("columncount:"+columncount);  

                    jpopupmenu popupmenu = new jpopupmenu();  

                    jmenuitem runm = new jmenuitem(requestpanel.action_command_run);  

                    jmenuitem cleanup_runm = new jmenuitem("清空后再运行");  

                    jmenuitem copyparameterm = new jmenuitem(requestpanel.action_command_copy_request_parameter);  

                    jmenuitem copyresponsem = new jmenuitem(requestpanel.action_command_copy_response);  

                    jmenuitem copyaccesstokenm = new jmenuitem("复制access_token");  

                    jmenuitem cleanupcellm = new jmenuitem("清空单元格");  

                    cleanupcellm.setactioncommand(menuutil2.action_str_cleanup_cell);  

                    jmenuitem sendpostm = new jmenuitem("打开网页发送post请求");  

                    jmenuitem copypanelm = new jmenuitem("复制请求panel");  

                    jmenuitem deletecurrentpanelm = new jmenuitem("删除当前请求panel");  

                    jmenuitem cleanresultm = new jmenuitem("清空结果");  

                    jmenuitem copyrequestinfom=new jmenuitem(requestpanel.action_command_copy_request_info);  

                    jmenuitem pasterequestinfom=new jmenuitem(requestpanel.action_command_paste_request_info);  

                    mytablemenulistener ymenuactionlistener = new mytablemenulistener(null,systemhwutil.negative_one  

                            ,systemhwutil.negative_one,currentrequestpanel2);  

                    runm.addactionlistener(ymenuactionlistener);  

                    cleanup_runm.addactionlistener(ymenuactionlistener);  

                    copyparameterm.addactionlistener(ymenuactionlistener);  

                    copyresponsem.addactionlistener(ymenuactionlistener);  

                    copyaccesstokenm.addactionlistener(ymenuactionlistener);  

                    cleanresultm.addactionlistener(ymenuactionlistener);  

                    copyrequestinfom.addactionlistener(ymenuactionlistener);  

                    pasterequestinfom.addactionlistener(ymenuactionlistener);  

                    cleanupcellm.addactionlistener(ymenuactionlistener);  

                    sendpostm.addactionlistener(ymenuactionlistener);  

                    copypanelm.addactionlistener(ymenuactionlistener);  

                    deletecurrentpanelm.addactionlistener(ymenuactionlistener);  

                    popupmenu.add(cleanup_runm);  

                    popupmenu.add(runm);  

                    popupmenu.add(copyparameterm);  

                    popupmenu.add(copyresponsem);  

                    popupmenu.add(copyaccesstokenm);  

                    popupmenu.add(cleanupcellm);  

                    popupmenu.add(sendpostm);  

                    popupmenu.add(copypanelm);  

                    popupmenu.add(deletecurrentpanelm);  

                    popupmenu.add(cleanresultm);  

                    popupmenu.add(copyrequestinfom);  

                    popupmenu.add(pasterequestinfom);  

                    popupmenu.show(e.getcomponent(), e.getx(), e.gety());  

//                    processevent(e);  

                }/*else if (e.getbutton() == mouseevent.button1&& e.getclickcount()==1){ 

                    system.out.println("左键"); 

//                  jtable.editcellat(rowcount, columncount,ne); 

                system.out.println("mousereleased"+(count++));  

            public void mouseentered(mouseevent e) {  

            public void mouseexited(mouseevent e) {  

            public void mousedragged(mouseevent e) {  

            public void mousemoved(mouseevent e) {  

            private void processevent(mouseevent e) {  

                // right-click on  

                if ((e.getmodifiers() & mouseevent.button3_mask) != 0) {  

                    // system.out.println(e.getmodifiers());  

                    // system.out.println("right-click on");  

                    int modifiers = e.getmodifiers();  

                    modifiers -= mouseevent.button3_mask;  

                    modifiers |= mouseevent.button1_mask;  

                    mouseevent ne = new mouseevent(e.getcomponent(), e.getid(),  

                            e.getwhen(), modifiers, e.getx(), e.gety(),  

                            e.getclickcount(), false);  

                    tabbedpane.dispatchevent(ne);// in order to trigger left-click  

                    // the event  

        };  

    }