Since your piece of code is too small to give the correct answer, I can think:
When you are inside jTextArea
update, is Packet
null? You can check it out.
When calling this jTextArea
method jTextArea
is there text on it? If none and Packet
are null, you will not see any result.
Edit: According to the comment:
To add text, use append , also read tutorial
Although I would expect setText
display text at least for the first time, see below for an example minimum code example:
import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField; public class TestJTextArea { static void init() { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); final JTextArea textArea = new JTextArea(); frame.add(textArea, BorderLayout.NORTH); final JTextField textField = new JTextField(); frame.add(textField,BorderLayout.CENTER); JButton button = new JButton("Add"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { textArea.setText(textField.getText()); } }); frame.add(button,BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public static void main(String[] args) { init(); } }
And with that, I also agree with @Hovercraft Full Of Eels that you might have a problem with Swing threads, or just use append to add text
source share