Java - How to add text in JTextPane using Document -


i want make console(jtextpane) in java application show application doing. had tried lot of times using different method failed...here part of code.

mainclass

private final form form;  println("downloading files...");  public void println(string line) {         system.out.println(line);         form.getconsole().print(line); } 

form(gui)

private tabconsole console;  tabbedpane.addtab("console", console);  public tabconsole getconsole() {         return console; } 

tabconsole

public void print(final string line) {         if (!swingutilities.iseventdispatchthread()) {           swingutilities.invokelater(new runnable()           {             public void run() {               tabconsole.this.print(line);             }           });           return;         }          document document = this.console.getdocument();         jscrollbar scrollbar = getverticalscrollbar();         boolean shouldscroll = false;          if (getviewport().getview() == this.console) {           shouldscroll = scrollbar.getvalue() + scrollbar.getsize().getheight() + monospaced.getsize() * 4 > scrollbar.getmaximum();         }         try         {           document.insertstring(document.getlength(), line, null);         } catch (badlocationexception localbadlocationexception) {         }         if (shouldscroll)           scrollbar.setvalue(2147483647);       } 

is wrong codes? helping.

rethrow badlocationexception runtimeexception, although code looks correct. error getting?

if text not showing up, updating wrong document. sure you're updating document used textarea, or whatever you're using display contents.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -