【问题标题】:append feature in JLabel like in JTextArea java?像在 JTextArea java 中一样在 JLabel 中附加功能?
【发布时间】:2014-04-09 15:13:46
【问题描述】:

是否有 JLabel 的附加功能,例如在 JTextArea 中?

JTextArea Text = new JTextArea("including; "); 
Text.append("button1,");

【问题讨论】:

    标签: java swing append jlabel settext


    【解决方案1】:

    不,但每次你想添加文本时都可以这样做

    label.setText(label.getText() + "text u want to append");
    

    【讨论】:

      【解决方案2】:

      如果你真的想要一个叫做.append(text)的方法,你可以创建自己的自定义标签

      public class MyLabel extends JLabel {
      
       public MyLabel(String text) {
          super(text);
       }
      
       public void append(String appendText) {
         setText(getText() + appendText);
       }
      }
      

      你可以创建你的标签:

      MyLabel myLabel = new MyLabel("First Text");
      myLabel.append("Appended Text");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-18
        • 1970-01-01
        • 2015-08-07
        • 1970-01-01
        • 1970-01-01
        • 2020-11-25
        • 1970-01-01
        相关资源
        最近更新 更多