gpt4 book ai didi

java - JTextPane 在上一行之后打印文本

转载 作者:行者123 更新时间:2023-12-02 05:59:52 25 4
gpt4 key购买 nike

我有一个带有 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;
}
}
//...

最佳答案

而不是做

Text.insertString(0, 消息 + "\n", 颜色);

这样做

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

0 是索引位置,即插入文本的位置。使用 Text.getLength(),它将始终插入到末尾。

有关更多信息,请参阅此:JTextPane appending a new string

关于java - JTextPane 在上一行之后打印文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22761312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com