0

Plz help.
I am working to create application kind of auto-suggestion. I am using JTextPane along with Jlist on PopupMenu. I am not able to get the Action Event on JList.
and other problem is that my KeyPress Event of JTextPane are getting overlapped with JList hence nothing is selected when Enter is pressed or even Mouse is clicked.
Plzzzzzzzz help as soon as Possible.

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by Ashwin Vasnai
0
public class ListListener implements ListSelectionListener {
        public void valueChanged(ListSelectionEvent e) {
         try{
                  popupMenu.setVisible(false);
             TextPane1.setText(wpop.putloc(jTextPane1.getText(),list.getSelectedValue().toString(),jTextPane1.getCaretPosition()));
               }
            catch(Exception ex)
            {
               
            }
        }
        
    }
0
private void ListPopUp(String str[])
    {
        
            model1=new DefaultListModel();
            size=model1.getSize();
            list =new JList();
            list.removeAll();
            list.addListSelectionListener(new ListListener());
            for(int i=0;i<str.length;i++)
             model1.addElement(str[i]);
            list.setModel(model1);

            int ht=(model1.getSize()*24);
            if(ht>250)
                ht=250;
            a.setPreferredSize(new Dimension(100,ht));
            list.setPreferredSize(new Dimension(75,model1.getSize()*12));
            a.setViewportView(list);
            
            popupMenu=new JPopupMenu("Popup");
            popupMenu.add(a);
            popupMenu.setInvoker(jTextPane1);
            ActionListener lis =new PopupActionListener();
          //popupMenu.setSize(40,model1.getSize()*12);
            //popupMenu.pack();
            //popupMenu.setPopupSize(null);
            popupMenu.show(jTextPane1, 30, 20);

            size=model1.getSize();

            jTextPane1.setRequestFocusEnabled(true);
            jTextPane1.grabFocus();
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.