如何在 JLabel 上附加新文本? [英] How do i append a new text at JLabel?

查看:22
本文介绍了如何在 JLabel 上附加新文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到了一些我需要使用 HTML 东西的 StackOverflow 问题.但是如果没有任何 HTML 东西,最简单的方法是什么.

I read, some StackOverflow questions that I need to use HTML stuffs. But what would be the easiest it without any of HTML stuff.

这是代码

label.setText(label.getText() + (String)boxTimes.getSelectedItem() + input);

这段代码会产生这个

我想要的是:

推荐答案

你必须知道一些基本的String格式:

You must know a bit of basic String format:

  • \n 换行
  • \t 标签
  • \n line break
  • \t tab

所以你的代码会是这样的:

So your code will be like:

String myLabel = 
      // 4
      label.getText() + "\n\n" + 
      // 7:00
      (String)boxTimes.getSelectedItem() + "\t" +
      // - Going out....
      "- " + input;

label.setText(myLabel);

但只要 JLabel 不接受 \n 作为 Abishek Manoharan 指出,您必须使用
.

But as long as JLabel does not accept \n as Abishek Manoharan pointed, you must use <br>.

String  myLabel = 
    "<html>" + 
        label.getText() + 
        "<br/><br/>" +
        (String)boxTimes.getSelectedItem() + " - " + input + 
    "</html>;

label.setText(myLabel);

这篇关于如何在 JLabel 上附加新文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆