首页 > 解决方案 > 在 JTextArea 中添加动态文本值

问题描述

我正在尝试添加动态文本值,它是 JTextArea 中的一个字符串,但是通过 methodname.add 或 methodname.addElement 的一些方法给了我一个错误。这是我正在尝试的代码部分。

代码:

 ipList = new JTextArea();
    ipList.setForeground(new Color(0, 0, 128));
    ipList.setFont(new Font("Calibri", Font.BOLD, 18));
    ipList.setBackground(new Color(245, 245, 245));
    scrollPane.setViewportView(ipList);

    byte[] ip = localhost.getAddress();
     for (int i = 1; i <= 254; i++)
     {
         ip[3] = (byte)i;
         InetAddress address = InetAddress.getByAddress(ip);
         String hostName = address.getHostName();
         if (address.isReachable(1000))
         {
              ipList.addElement(address.toString().split("/")[1]+ " "+"Device Name: "+hostName);
              ipList.addElement(address.hostName());
            // System.out.println(address.toString().split("/")[1]+ " "+"Device Name: "+hostName);
            // System.out.println(address.getHostName());
         }
     }

标签: javaeclipsejframe

解决方案


推荐阅读