我有一个带有问题内容的二维数组,它在启动时加载到表单上。我希望在25个字符后打破该行,然后添加一个新行,并将其设置为JLabel
文本。 " \ n"不起作用,所以我尝试了html格式化,它只显示JLabel
上文本的第一个字符。
这是我目前的代码:
boolean alreadyset = false;
if(questions[currentQuestion-1][1].length() > 25){
char[] bytevalues = questions[currentQuestion-1][1].toCharArray();
int counter = 0;
String currentText;
for(char x: bytevalues){
if(counter==0)
jLabel5.setText(String.valueOf(x));
else if(counter % 25 == 0){
currentText = jLabel5.getText();
jLabel5.setText("<html>"+ currentText + "<br>" + String.valueOf(x)+"</html>");
}
else if(counter!=0){
currentText = jLabel5.getText();
jLabel5.setText("<html>"+currentText + String.valueOf(x)+"</html>");
}
counter++;
}
alreadyset = true;
感谢您提前的时间!