Java read display txt content (Swing), JTextArea
Public classTxtswingextendsJFrame {PrivateJTextArea Textareaoutput; PublicTxtswing ()throwsIOException {Super("TXT"); Setdefaultcloseoperation (Exit_on_close); Getcontentpane (). setlayout (Newjava.awt.FlowLayout ()); Textareaoutput=NewJTextArea ("111", 45, 80); Textareaoutput.setselectedtextcolor (color.red); Textareaoutput.setlinewrap (true);//Activate the line wrap featureTextareaoutput.setwrapstyleword (true);//Activate break word functionBufferedReader reader =NewBufferedReader (NewFileReader ("Test.txt")); String Str=Reader.readline (); String End=NULL; while(str! =NULL) ) {End= end + str + "\ n"; STR=Reader.readline (); } textareaoutput.settext (end); Getcontentpane (). Add (Textareaoutput); SetSize (1024, 768); } /** * @paramargs *@throwsIOException*/ Public Static voidMain (string[] args)throwsIOException {txtswing TM=Newtxtswing (); Tm.setvisible (true); }}
Java read display txt content (Swing)