给Tab增加事件

tab对应的类是:javax.swing.JTabbedPane

1,增加双击事件:

Java代码  

  1. tabbedPane_22.addMouseListener(new MouseAdapter() {  
  2.             private int heightLevel=0;  
  3.             @Override  
  4.             public void mouseReleased(MouseEvent e) {  
  5.             }  
  6.               
  7.             @Override  
  8.             public void mousePressed(MouseEvent e) {  
  9.             }  
  10.               
  11.               
  12.             @Override  
  13.             public void mouseClicked(MouseEvent e) {  
  14.                 JTabbedPane tabbedPane = (JTabbedPane) e.getSource();  
  15.                 int selectedIndex = tabbedPane.getSelectedIndex();  
  16.                 //当前选择的标签页  
  17.                 Component selectedTab= tabbedPane.getComponentAt(selectedIndex);  
  18.                 if(!ValueWidget.isNullOrEmpty(selectedTab)&&jsonFormattedPane==selectedTab){  
  19.                       
  20.                     if(e.getClickCount()==2){  
  21.                         switch (heightLevel%3) {  
  22.                         case 0:  
  23.                             splitPane_out.setDividerLocation(getDividerHeight()[0]);  
  24.                             break;  
  25.                         case 1:  
  26.                             splitPane_out.setDividerLocation(15);  
  27.                             break;  
  28.                         case 2:  
  29.                             splitPane_inner.setDividerLocation(getDividerHeight()[0]);  
  30.                             splitPane_out.setDividerLocation(getDividerHeight()[1]);  
  31.                             RequestPanel.this.repaint();  
  32.                             break;  
  33.                         default:  
  34.                             break;  
  35.                         }  
  36.                         heightLevel++;  
  37.                     }  
  38.                       
  39.                 }  
  40.                   
  41.             }  
  42.         });  

 

2,增加右键菜单

Java代码  

  1. tabbedPane_2.addMouseListener(getMouseInputListener(tabbedPane_2, this));  

 监听器:

Java代码  

  1. public static MouseInputListener getMouseInputListener(final JTabbedPane tabbedPane  
  2.             ,final AutoTestPanel autoTestPanel) {  
  3.           
  4.         return new MouseInputListener() {  
  5.             public  int count;  
  6.             public void mouseClicked(MouseEvent e) {  
  7.                 /*if(e.getClickCount()==1){ 
  8.                     final int rowCount = jTable.getSelectedRow(); 
  9.                     final int columnCount=jTable.getSelectedColumn(); 
  10.                     int modifiers = e.getModifiers(); 
  11.                     modifiers -= MouseEvent.BUTTON3_MASK; 
  12.                     modifiers |= MouseEvent.FOCUS_EVENT_MASK; 
  13.                     MouseEvent ne = new MouseEvent(e.getComponent(), e.getID(), 
  14.                             e.getWhen(), modifiers, e.getX(), e.getY(), 
  15.                             2, false); 
  16. //                  processEvent(ne); 
  17.                     jTable.editCellAt(rowCount, columnCount,ne); 
  18. //                  CellEditor cellEditor=jTable.getCellEditor(rowCount, columnCount); 
  19. //                  cellEditor.shouldSelectCell(ne); 
  20.                     jTable.dispatchEvent(ne); 
  21.                 }*/  
  22.                 System.out.println("mouseClicked"+(count++));  
  23.                 processEvent(e);  
  24.                   
  25.             }  
  26.             /*** 
  27.              * in order to trigger Left-click the event 
  28.              */  
  29.             public void mousePressed(MouseEvent e) {  
  30.                 processEvent(e);// is necessary!!!  
  31.                 System.out.println("mousePressed"+(count++));  
  32.             }  
  33.   
  34.             public void mouseReleased(MouseEvent e) {  
  35.                   
  36.                 RequestPanel currentRequestPanel2=(RequestPanel)tabbedPane.getSelectedComponent();  
  37.                 if(ValueWidget.isNullOrEmpty(currentRequestPanel2)){  
  38.                     currentRequestPanel2=autoTestPanel.getCurrentRequestPanel();  
  39.                 }  
  40.                 if (e.getButton() == MouseEvent.BUTTON3) {// right click  
  41. //                  processEvent(e);  
  42.                       
  43.                     // System.out.println("row:" + rowCount);  
  44.                     //右键点击表格时,点击的单元格,正常情况返回的是String  
  45. //                  System.out.println("rowCount:"+rowCount);  
  46. //                  System.out.println("columnCount:"+columnCount);  
  47.                       
  48.                       
  49.                     JPopupMenu popupmenu = new JPopupMenu();  
  50.                     JMenuItem runM = new JMenuItem(RequestPanel.ACTION_COMMAND_RUN);  
  51.                     JMenuItem cleanUp_runM = new JMenuItem("清空后再运行");  
  52.                     JMenuItem copyParameterM = new JMenuItem(RequestPanel.ACTION_COMMAND_COPY_REQUEST_PARAMETER);  
  53.                     JMenuItem copyResponseM = new JMenuItem(RequestPanel.ACTION_COMMAND_COPY_RESPONSE);  
  54.                     JMenuItem copyAccessTokenM = new JMenuItem("复制access_token");  
  55.                     JMenuItem cleanUpCellM = new JMenuItem("清空单元格");  
  56.                     cleanUpCellM.setActionCommand(MenuUtil2.ACTION_STR_CLEANUP_CELL);  
  57.                      
  58.                     JMenuItem sendPostM = new JMenuItem("打开网页发送POST请求");  
  59.                     JMenuItem copyPanelM = new JMenuItem("复制请求panel");  
  60.                     JMenuItem deleteCurrentPanelM = new JMenuItem("删除当前请求panel");  
  61.                       
  62.                     JMenuItem cleanResultM = new JMenuItem("清空结果");  
  63.                     JMenuItem copyRequestInfoM=new JMenuItem(RequestPanel.ACTION_COMMAND_COPY_REQUEST_INFO);  
  64.                     JMenuItem pasteRequestInfoM=new JMenuItem(RequestPanel.ACTION_COMMAND_PASTE_REQUEST_INFO);  
  65.                       
  66.                     MyTableMenuListener yMenuActionListener = new MyTableMenuListener(null,SystemHWUtil.NEGATIVE_ONE  
  67.                             ,SystemHWUtil.NEGATIVE_ONE,currentRequestPanel2);  
  68.                     runM.addActionListener(yMenuActionListener);  
  69.                     cleanUp_runM.addActionListener(yMenuActionListener);  
  70.                     copyParameterM.addActionListener(yMenuActionListener);  
  71.                     copyResponseM.addActionListener(yMenuActionListener);  
  72.                     copyAccessTokenM.addActionListener(yMenuActionListener);  
  73.                     cleanResultM.addActionListener(yMenuActionListener);  
  74.                     copyRequestInfoM.addActionListener(yMenuActionListener);  
  75.                     pasteRequestInfoM.addActionListener(yMenuActionListener);  
  76.                     cleanUpCellM.addActionListener(yMenuActionListener);  
  77.                     sendPostM.addActionListener(yMenuActionListener);  
  78.                     copyPanelM.addActionListener(yMenuActionListener);  
  79.                     deleteCurrentPanelM.addActionListener(yMenuActionListener);  
  80.                       
  81.                     popupmenu.add(cleanUp_runM);  
  82.                     popupmenu.add(runM);  
  83.                     popupmenu.add(copyParameterM);  
  84.                     popupmenu.add(copyResponseM);  
  85.                     popupmenu.add(copyAccessTokenM);  
  86.                     popupmenu.add(cleanUpCellM);  
  87.                     popupmenu.add(sendPostM);  
  88.                     popupmenu.add(copyPanelM);  
  89.                     popupmenu.add(deleteCurrentPanelM);  
  90.                     popupmenu.add(cleanResultM);  
  91.                     popupmenu.add(copyRequestInfoM);  
  92.                     popupmenu.add(pasteRequestInfoM);  
  93.                     popupmenu.show(e.getComponent(), e.getX(), e.getY());  
  94. //                    processEvent(e);  
  95.                 }/*else if (e.getButton() == MouseEvent.BUTTON1&& e.getClickCount()==1){ 
  96.                     System.out.println("左键"); 
  97.                     int modifiers = e.getModifiers(); 
  98.                     modifiers |= MouseEvent.FOCUS_EVENT_MASK; 
  99.                     MouseEvent ne = new MouseEvent(e.getComponent(), e.getID(), 
  100.                             e.getWhen(), modifiers, e.getX(), e.getY(), 
  101.                             2, false); 
  102.                      
  103. //                  processEvent(ne); 
  104. //                  jTable.editCellAt(rowCount, columnCount,ne); 
  105. //                  CellEditor cellEditor=jTable.getCellEditor(rowCount, columnCount); 
  106. //                  cellEditor.shouldSelectCell(ne); 
  107.                     jTable.dispatchEvent(ne); 
  108.                 }*/  
  109.                 System.out.println("mouseReleased"+(count++));  
  110.             }  
  111.   
  112.             public void mouseEntered(MouseEvent e) {  
  113.                 processEvent(e);  
  114.             }  
  115.   
  116.             public void mouseExited(MouseEvent e) {  
  117.                 processEvent(e);  
  118.             }  
  119.   
  120.             public void mouseDragged(MouseEvent e) {  
  121.                 processEvent(e);  
  122.             }  
  123.   
  124.             public void mouseMoved(MouseEvent e) {  
  125.                 processEvent(e);  
  126.             }  
  127.   
  128.             private void processEvent(MouseEvent e) {  
  129.                 // Right-click on  
  130.                 if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {  
  131.                     // System.out.println(e.getModifiers());  
  132.                     // System.out.println("Right-click on");  
  133.                     int modifiers = e.getModifiers();  
  134.                     modifiers -= MouseEvent.BUTTON3_MASK;  
  135.                     modifiers |= MouseEvent.BUTTON1_MASK;  
  136.                     MouseEvent ne = new MouseEvent(e.getComponent(), e.getID(),  
  137.                             e.getWhen(), modifiers, e.getX(), e.getY(),  
  138.                             e.getClickCount(), false);  
  139.                     tabbedPane.dispatchEvent(ne);// in order to trigger Left-click  
  140.                     // the event  
  141.                 }  
  142.             }  
  143.         };  
  144.     }  

 

时间: 2024-08-22 15:14:14

给Tab增加事件的相关文章

给VML增加事件_VML相关

VML 和 HTML 的紧密结合,使的给 VML 增加事件变得很容易.所有的 HTML 里面的事件都可以应用到 VML 中间来!下面的例子是演示:当鼠标移动到圆的时候,圆就跟着鼠标移动了,当鼠标点击后,圆停止移动. <v:oval id="circle" style="position:relative;width:100;height:80;" onmouseover="move()" fillcolor=red /><scr

[Windows编程] 如何截获Alt+Tab事件

Windows 中 Alt + Tab 组合键被用来在各个程序之间切换. 因此,该键盘消 息 (WM_KEYDOWN/UP) 是直接发给系统内核, 在应用程序中的消息循环中截获不 到. 一个常见问题是,可是有的应用程序想在被Alt+TAB 切换到后台之间做点事情 , 这时候该怎么办? 方案之一就是用底层的键盘钩子,截获整个系统的键盘输入.但这样做会导致 一些效率以及稳定性问题. 另外一个比较方便安全的方案就是用 Windows Accessbility API 的 SetWinEventHook

Android实现为Tab添加Menu的方法_Android

本文实例讲述了Android实现为Tab添加Menu的方法.分享给大家供大家参考,具体如下: 在Android中,TabActivity类中没有与Menu有关的方法,所以如果单独使用TabActivity进行开发时,是无法创建菜单项的.为了给Tab增加菜单,有如下两种方法: 1. 主事件继承Activity.这样就可以在主事件中直接重写OnCreateOptionsMenu方法,为程序添加Menu.如果每个Tab需要有不同的Menu,可以为TabHost添加一个OnTabChangedListe

Android实现为Tab添加Menu的方法

本文实例讲述了Android实现为Tab添加Menu的方法.分享给大家供大家参考,具体如下: 在Android中,TabActivity类中没有与Menu有关的方法,所以如果单独使用TabActivity进行开发时,是无法创建菜单项的.为了给Tab增加菜单,有如下两种方法: 1. 主事件继承Activity.这样就可以在主事件中直接重写OnCreateOptionsMenu方法,为程序添加Menu.如果每个Tab需要有不同的Menu,可以为TabHost添加一个OnTabChangedListe

ASP.NET用户控件返回事件的方法

asp.net|控件 ASP.NET用户控件一般适用于产生相对静态的内容,所以没有builtin的事件支持.本文讨论用户控件返回事件的方法. 假定用户控件(UserControl.ascx)中包含按钮控件AButton,希望实现按AButton按钮时,包含该用户控件的页面可以接收到事件.为此,小鸡射手在用户控件和页面的代码中分别作了处理. UserControl.ascx.cs中的处理: 1. 定义public的事件委托,如ClickEventHandler; 2. 在UserControl类中

Java进阶学习(九) 事件响应

在GUI中,我们看到了如何用图形树来组织一个图形界面.然而,这样的图形界面是静态的.我们无法互动的对该界面进行操作.GUI的图形元素需要增加事件响应(event handling),才能得到一个动态的图形化界面. 元素, 事件, 监听器 我们在GUI一文中提到了许多图形元素.有一些事件(Event)可能发生在这些图形元素上,比如: 点击按钮 拖动滚动条 选择菜单 Java中的事件使用对象表示,比如ActionEvent.每个事件有作用的图形对象,比如按钮,滚动条,菜单. 所谓互动的GUI,是指当

Ext组件的使用和事件;;;;

问题描述 Ext组件的使用和事件:::: Ext组件创建完毕之后,还可以添加配置项吗(比如:通过ID获得panel对象,之后,可以给这个对象添加配置项吗) 解决方案 组件创建后,可以修改配置项的东西,可以通过本身组件的一些方法进行配置,例如grid可以通过reconfigure方法. 组件创建后,如果要监控事件,可以通过on方式,增加事件以及事件处理函数即可 解决方案二: EXT的自定义事件使用ext2.0中组件(paneltabPanelbuttonwindow)的使用(3) 解决方案三: 可

深入浅出事件流处理NEsper(二)

NEsper使用的事件类型来描述事件的类型信息.你的应用在启动时可能预先配置定义事件类型,或者在运行时通过API或EPL语法动态的增加事件类型. EPL中的create schema 的语法允许在运行时用EPL申明一个事件类型. 2.1事件对象 事件是过去发生的动作或状态变化的一个不可改变的记录.事件属性捕捉事件的状态信息. 在ESPER中,事件是可以被描述成以下任何一种CLR对象: NEsper为声明一个事件提供了多种的选择,没有绝对的需要用户去创建一个CLR对象来代表一个事件.事件表达有以下

jquery 给div动态增加到css方法

$().css教程('','');置所有匹配的元素中样式属性的值. $(selector).css(name,value); 下面看一下给一个 $('.aa').css('display','none'); <div id='aa'>这是内容</div> 下面看一个简单的jquery显示隐藏函数 function switchcontent(switchtype,switchid){  $('._content').css('display','none');  $('#_cont