2014-03-31 30 views
0

我得到了一個帶有JTextPane的程序。我想要在其中打印時出現問題。每一次,它都會在第一行打印,然後將其餘的打印下來。 我怎樣才能讓它在文本的最後打印?JTextPane在上一行之後打印文本

我得到這個:

//... 

public static enum Level { 
    CLASSIC, 
    MAJ, 
    AJOUT, 
    SUPRESSION, 
    CONFIG; 
} 

public static void add(Level level,String Message){ 
    switch(level){ 
     case CLASSIC: 
      try{ 
       Color BLACK = new Color(0, 0, 0); 
       StyleConstants.setForeground(Colors, BLACK); 
       Text.insertString(0, "\n\t- Mise à jour # " + Message + " -\n\n", Colors); 
      }catch(Exception e) { ConsoleError(); } 
      break; 
     case MAJ: 
      try{ 
       Color ORANGE = new Color(252, 156, 51); 
       StyleConstants.setForeground(Colors, ORANGE); 
       Text.insertString(0, Message + "\n", Colors); 
      }catch(Exception e) { ConsoleError(); } 
      break; 
     case AJOUT: 
      Color GREEN = new Color(58, 157, 52); 
      StyleConstants.setForeground(Colors, GREEN); 
      try{ 
       Text.insertString(0, Message + "\n", Colors); 
      }catch(Exception e) { ConsoleError(); } 
      break; 
     case SUPRESSION: 
      Color RED = new Color(183, 19, 0); 
      StyleConstants.setForeground(Colors, RED); 
      try{ 
       Text.insertString(0, Message + "\n", Colors); 
      }catch(Exception e) { ConsoleError(); } 
      break; 
     case CONFIG: 
      Color BLACK = new Color(0, 0, 0); 
      StyleConstants.setForeground(Colors, BLACK); 
      try{ 
       Text.insertString(0, Message + "\n", Colors); 
      }catch(Exception e) { ConsoleError(); } 
      break; 
    } 
} 
//... 

回答

2

而不是做

Text.insertString(0, Message + "\n", Colors);

做這個

Text.insertString(Text.getLength(), Message + "\n", Colors)

的0是索引位置,其中文本插入。使用Text.getLength(),它將始終插入到最後。

查看更多信息:JTextPane appending a new string