2014-02-17 11 views
-3

如何將主機的每一行放入消息正文中?我與JTextArea工作。如何在JTextArea中的多行上拆分數據?

String host = InetAddress.getLocalHost().getHostName().toString(); 
texto_recepcion.setText(host + texto_recepcion.getText() + dpRecepcion.getAddress() + " " + mensaje_recibido + "\n"); 

現在它是如何:

enter image description here

+0

我不知道你正在嘗試做的。你能提供更多的信息嗎? – Keppil

+0

我正在做一個聊天節目,我想下面的 「主機/ IP /消息」。 由用戶發送的每個消息,但我的主機覆蓋 例如: 第一消息中發送的主機=/IP /消息 第二消息中發送=主機/主機/ IP /消息 IP /消息 –

+0

@YoelMacia:我對您的帖子進行了一些更改,這可能會使您受益,因爲它會爲將來的問題提供材料。更具體地說:堅持你的問題。你的問題與多播的主機沒有任何關係,它是關於通過「JTextArea」中的多行分割數據(它與數據表示無關)。通過達到目的,你會得到更合適的迴應。同樣適用於標記:標記與問題相關的標記。最後:使用反引號來表示代碼元素,這樣更容易閱讀英文和代碼。 –

回答

1

我用附加函數解決了我的問題。

String host = InetAddress.getLocalHost().getHostName().toString(); 

texto_recepcion.append(host); // ***Use the function append for solve the problem*** 

texto_recepcion.setText(texto_recepcion.getText() + dpRecepcion.getAddress() + " " + mensaje_recibido + "\n"); 

非常感謝

0

你爲什麼不添加換行符 「\ n」 字符串的開始?

texto_recepcion.setText("\n" + host + texto_recepcion.getText() + dpRecepcion.getAddress() + " " + mensaje_recibido); 
+0

不,這是你的結果.. 。
的MacBook-PRO-DE-Yoel.local 的MacBook-PRO-DE-Yoel.local/192.168.1.132第一消息 /192.168.1.132第二消息 –

+0

什麼樣的控制是'texto_recepcion'?它是一個沒有多行的文本框? – alex

+0

JTextArea,但我已經解決了這個問題。使用追加功能。 –