java - I want to Print multiple lines of Text using a JTextPane to a window -


i've search question in different wording past day or 2 , can not solve :/,

i have window pops on screen looks command prompt there 2 buttons run , stop. anyways have on screen once press start starts "scanning files" says "scanning 1-1900 something" counts 1900 , says scan completed, after want text go under existing text , write multiple lines of text mess friend example.

{ scan completed "wait time inbetween each line of text" hack initialized "wait time inbetween each line of text" hack installing... "wait time inbetween each line of text" hack installed ect } 

hopefully can me, every 1 looked @ did not work code :/ i'm new code so...

thanks in advance anyways here code not long :p.

   public static void main(string[] args) throws ioexception {          jframe frame = new jframe("happy monday v0.05");         container contentpane = frame.getcontentpane();          jtextpane jta = new jtextpane();          jbutton button = new jbutton("run");         jbutton buttonstop = new jbutton("stop");           contentpane.add(button);         contentpane.add(buttonstop);            button.setbounds(-1,283,465,40);         buttonstop.setbounds(465,283,469,40);          frame.add(jta).setbackground(color.black);         console(jta);          //window                 frame.setsize(950, 650 / 16 * 9);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setlocationrelativeto(null);         frame.setvisible(true);              button.addactionlistener(new actionlistener(){             @override             public void actionperformed(actionevent e) {                 new swingworker<void, object>(){                     @override                     protected void doinbackground() throws exception {                         outputtest("scanning...");                         return null;                      }}.execute();             }});      }      //testing outputs:/     public static void outputtest(string msg){         for(int i=0;i<1969;i++){             system.out.println(i+" "+msg);             try {                 thread.sleep(01);                 system.out.println("scan complete");              } catch (interruptedexception ex) {                 ex.printstacktrace();             }                }     }      public static void console(final jtextpane area) throws ioexception {         area.setcontenttype("text/html");         final pipedinputstream outpipe = new pipedinputstream();         system.setout(new printstream(new pipedoutputstream(outpipe), true));                new swingworker<void, string>() {             @override             protected void doinbackground() throws exception {                 scanner s = new scanner(outpipe);                 while (s.hasnextline()){                     string line = s.nextline();                     publish(line + "\n");                 }                 return null;             }             @override             protected void process(list<string> chunks) {                 (string line : chunks){                     area.settext("<font size=\"5\" color=\"green\">"+line+"</font>");                     }                     }         }.execute();     }  } 

the settext method not appends line.it overrides text.so previous text won't visible.

you have append text, have find mechanism append method not exist. in console method, can add these:

document doc = area.getdocument(); thread.sleep(2000); doc.insertstring(doc.getlength(),"hack installing....\n", null); thread.sleep(2000); doc.insertstring(doc.getlength(),"hack installed...\n", null); 

note:

calling thread.sleep() not recommended directly using multi-threaded environment.it's example haven't scanned code.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -