JPopupMenu popup = new JPopupMenu();
        JCheckBoxMenuItem showLabelItem = null;
        JCheckBoxMenuItem showLampItem = null;
        showLabelItem=new JCheckBoxMenuItem("11111");
        showLabelItem.addActionListener(showLabel);
        showLabelItem.setSelected(false);
        popup.add(showLabelItem);
        showLampItem = new JCheckBoxMenuItem("22222");
        showLampItem.setEnabled(false);
        showLampItem.setSelected(false);
        showLampItem.addActionListener(showLamp);
        popup.add(showLampItem);         ActionListener showLamp = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showLamp_actionPerformed();
            }
        };应该对你有帮助吧。另外你描述的是不大清楚。

解决方案 »

  1.   

    另外那个问题:getCaretPosition
    public int getCaretPosition() Returns the position of the text insertion caret for the text component. Returns:
    the position of the text insertion caret for the text component >= 0
      

  2.   

    不好意思,再说明一下。我的菜单是Edit-->insert-->tag-->tagName其中tagName是一组数据(从XML中读取),现在我要在菜单上点击某一个tagName,然后在JTextPane编辑框中光标所在位置上添入一些数据。问题是点击tagName的事件都找不到,另外一个问题就是在编辑框中光标所在位
    置上添入数据怎么来?也就是如何捕捉光标位置。
    这样说是不是清楚一点。