Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing text to the console from JTextArea

Status
Not open for further replies.

sjohri214

Programmer
Jul 19, 2002
24
0
0
GB
Hi,

I'm having a problem getting the text i have entered within a JTextArea to print to the screen (console).
When i enter text in the JTextArea or open a file into the JTextArea (using a Filechooser) and then click on a JRadioButton - the value entered within the JTextArea should print out to the screen, but all that prints out is "null".

Any Suggestions would be much appreciated,

Thanks Again for any help,

public void openFile(){

fc.setFileSelectionMode(fc.FILES_ONLY);
int returnVal = fc.ShowOpenDialog(Frame1.this);
if(returnVal == fc.APPROVE_OPTION){
File file = fc.getSelectedFile();
if(file == null || file.getName().equals("")
JOptionPane.showMessageDialog(this, "Invalid File Name", "File name is Invalid", JOptionPane.ERROR_MESSAGE);
else {
try {
inp = new BufferedReader(new FileReader(file);
StringBuffer buffer = new StringBuffer();
while ((any = inp.readLine()) ! = null){
buffer.append (any + "\n");
jTextArea1.append(buffer.toString());
}
}
catch (IOException ioe){
JOptionPane.showMEssageDialog(this, "File Does not exist", "Invalid File name", JOptionPane.ERROR_MESSAGE);
}
}
}
public class ButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
String text1 = e.getActionCommand();

if (text1.equals("Upload Sequence")){
openFile();
}
else if (text1.equals ("PIPMAKER Analysis")){
System.out.println(any);
}
}
}
 
The condition for the break on your while statement is that any is eventually null, so any should be null by the time you print out the value.

Try jTextArea1.getText() instead, if you want the entire value of the textbox.
 
Thanks for the reply,

That did the trick just fine.

Thanks Again

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top