private void setCategory(String str) {
        String[] cats = tCategories.getText().split(";");

        int caret = tCategories.getCaretPosition()+1;
        int n = 0, length = cats[0].length();

        for(int i=0; i<cats.length-1; ++i) {
            if(caret>length+1) {
                ++n;
                ++length; //";"
                length+=cats[i+1].length();
            }
            else break;
        }

        //set text
        cats[n] = str;
        String text = "";
        for(String s : cats)
            text += s + ";";
        tCategories.setText(text);
        stop=true;
        //tCategories.setCaretPosition(caret);
    }