java - How to read last word or latest word in JTextArea -


i making source code editor using jtextarea.in want following task." while user typing on editor window(jtextarea),each , every time updated text(last word) should compare set of words in database, if matches 1 of word definition open in new popup frame." coding following

string str = textarea.gettext();         class.forname(driver).newinstance();         conn = drivermanager.getconnection(url+dbname,username,password);         string stm="select url pingatabl functn=?";         preparedstatement st = conn.preparestatement(stm);         st.setstring(1, str);          //excuting query         resultset rs = st.executequery();         if (rs.next()) {         string s = rs.getstring(1);         //sets records in frame         jframe fm = new jframe();         fm.setvisible(true);         fm.setsize(500,750);         jeditorpane jm = new jeditorpane();         fm.add(jm);         jm.setpage(classloader.getsystemresource(s)); 

in above coding string str = textarea.gettext(); reads text in textarea.. need last word only. how can latest word jtextarea..

you can use following code block if want last word in testarea

string[] wordsarray = textarea.gettext().split("\\s+"); string lastword = wordsarray[wordsarray.length - 1]; 

but if want last updated word have use listener that. check on documentlistener , documentevent http://docs.oracle.com/javase/7/docs/api/javax/swing/event/documentlistener.html http://docs.oracle.com/javase/7/docs/api/javax/swing/event/documentevent.html


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -