powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / PopupMenu
4 сообщений из 4, страница 1 из 1
PopupMenu
    #33435806
GlukOza
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот немогу разобраться почему віскакивает ошибка:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
     int  pi =  5 ;
    ArrayList po =  new  ArrayList();
     while  (poind.next())
    {
          po.add(poind.getString( 2 ).trim()+"  "+poind.getString( 1 ).trim());
    }
    String poSTR = ((String)po.get(pi)).substring( 0 , 5 );
    pif.setText(poSTR);


// Здесь відет такую ошибку:

javax.swing.text.BadLocationException: Invalid location
	at javax.swing.text.GapContent.getChars(GapContent.java: 169 )
...
Рейтинг: 0 / 0
PopupMenu
    #33435819
GlukOza
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Забыла еще прибавить:

Код: plaintext
1.
2.
3.
   
    poind.getString( 2 ).trim()+"  "+poind.getString( 1 ).trim())
    

В результате имеем:

"02105 5/2"
...
Рейтинг: 0 / 0
PopupMenu
    #33435844
Фотография А.Грасоff™
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
название топика как-то связано с содержанием?

А.Грасоff™
...
Рейтинг: 0 / 0
PopupMenu
    #33435910
GlukOza
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А.Грасоff™название топика как-то связано с содержанием?

А.Грасоff™

Связано.

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
  new  ListAutoCompleter(pif,po,true);
 pif.addKeyListener( new  KeyAdapter()
                    {
                         public   void  keyReleased(KeyEvent e)
                        {
                             if  (e.getKeyCode()== 10 )
                            {
                                 int  pi = po.indexOf(pif.getText().trim());
                                System.out.println(pi);
                                System.out.println((String)po.get(pi));
                                String poSTR = ((String)po.get(pi)).substring( 0 , 5 );
                                pif.setText(poSTR);
                                adf.setText(((String)po.get(pi)).substring( 6 ,((String)po.get(pi)).trim().length()));
                                pifLAC.popup.setVisible(false);
                                adf.requestFocus();
                            }
                        }
                    });


А теперь код : ListAutoCompleter


Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
 import  javax.swing.text.BadLocationException;
 import  javax.swing.text.JTextComponent;
 import  java.util.ArrayList;
 import  java.util.List;
 import  java.util.Iterator;

 public   class  ListAutoCompleter  extends  AutoCompleter{

     private  List completionList;
     private   boolean  ignoreCase;

     public  ListAutoCompleter(JTextComponent comp, List completionList,  boolean  ignoreCase){
         super (comp);
         this .completionList = completionList;
         this .ignoreCase = ignoreCase;
    }

    // update classes model depending on the data in textfield
     protected   boolean  updateListData(){
        String value = textComp.getText();

         int  substringLen = value.length();

        List possibleStrings =  new  ArrayList();
        Iterator iter = completionList.iterator();
         while (iter.hasNext()){
            String listEntry = (String)iter.next();
             if (substringLen>=listEntry.length())
                 continue ;

             if (ignoreCase){
                 if (value.equalsIgnoreCase(listEntry.substring( 0 , substringLen)))
                    possibleStrings.add(listEntry);
            } else   if (listEntry.startsWith(value))
                possibleStrings.add(listEntry);
        }

        list.setListData(possibleStrings.toArray());
         return  true;
    }

    // user has selected some item in the classes. update textfield accordingly...
     protected   void  acceptedListItem(String selected){
         if (selected== null )
             return ;

         int  prefixlen = textComp.getDocument().getLength();

         try {
            textComp.getDocument().insertString(textComp.getCaretPosition(), selected.substring(prefixlen),  null );
        }  catch (BadLocationException e){
            e.printStackTrace();
        }
        popup.setVisible(false);
    }
}
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / PopupMenu
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]