我正在尝试添加动态文本值,这是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());
}
}