Program to read the text from a file and display it on a JFrame.

Program to read the text from a file and display it on a JFrame.

import javax.swing.*;
import java.io.*;
import java.lang.*;
import java.awt.*;
class MegaViewer1 extends JFrame
{
    JTabbedPane jtp1=new JTabbedPane();
    JPanel jp1=new JPanel();
    JTextArea t1=new JTextArea();
    MegaViewer1() throws Exception
    {
        super("MegaViewer");
        FileReader f=new FileReader("Eight.java");
        BufferedReader brk=new BufferedReader(f);       
        String s;
        while((s=brk.readLine())!=null)
        t1.setText(s);
        jp1.add(t1);
        jtp1.addTab("Tab1",t1);
        add(jtp1);  
    }
    public static void main(String args[]) throws Exception
    {
        MegaViewer1 mv1=new MegaViewer1();
        mv1.pack();
        mv1.setVisible(true);   
        mv1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    }
}

The issue with this is only the last character is been displayed on the tabbed frame(i.e a "}"). Any suggestions ?

View Answers

May 3, 2012 at 11:31 AM

Use append() method instead of setText().

Here is your modified code:

import javax.swing.*;
import java.io.*;
import java.lang.*;
import java.awt.*;
class MegaViewer1 extends JFrame
{
    JTabbedPane jtp1=new JTabbedPane();
    JPanel jp1=new JPanel();
    JTextArea t1=new JTextArea();
    MegaViewer1() throws Exception
    {
        super("MegaViewer");
        FileReader f=new FileReader("A.java");
        BufferedReader brk=new BufferedReader(f);       
        String s;
        while((s=brk.readLine())!=null){
        t1.append(s);
        }
        jp1.add(t1);
        jtp1.addTab("Tab1",t1);
        add(jtp1);  
    }
    public static void main(String args[]) throws Exception
    {
        MegaViewer1 mv1=new MegaViewer1();
        mv1.pack();
        mv1.setVisible(true);   
        mv1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    }
}









Related Tutorials/Questions & Answers:
Program to read the text from a file and display it on a JFrame.
Program to read the text from a file and display it on a JFrame.  ...*; class MegaViewer1 extends JFrame { JTabbedPane jtp1=new JTabbedPane... java.lang.*; import java.awt.*; class MegaViewer1 extends JFrame { JTabbedPane jtp1
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
Advertisements
Read Lines from text file
read from the text file and displays the output as desired. Unable to read the rest...Read Lines from text file  Here's a brief desc of what my Java code does .. I'm using BufferedReader to read lines from a text files and split each
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
Java program to read a text file and write to another file
Java program to read a text file and write to another file - Creating a simple program for reading text file and writing data into another text file... and we want to copy the content into another text file from our Java program
Read specific column data from text file in java
Read specific column data from text file in java  My question is if my text file contain 15 columns and i want read specific column data from that text file then what code i should do
Java Read Lines from Text File and Output in Reverse order to a Different Text File
Java Read Lines from Text File and Output in Reverse order to a Different Text File  I need to read a file that was selected by the user using... to display the names and path on the console. But I can not get the file to read line
Read File from specified path in Java
the file, the program will read text data line by line and print on the console... is a complete example of the program that reads a text file from the disk path and print...How to read a file from a specified path in Java? After learning so many
display multiple images from postgres database in jframe
display multiple images from postgres database in jframe  i just want to display multiple images on jframe by firing a query on postgres database
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Steps to read text file in pyspark
Steps to read text file in pyspark  Hi, I am learning to write program in PySpark. I want to simply read a text file in Pyspark and then try some code. What are the Steps to read text file in pyspark? How much time it takes
Read Specific Line from file Using Java
Read Specific Line from file Using Java Here we are going to read a specific line from the text file. For this we have created a for loop to read lines 1 to 10 from the text file. If the loop reached fifth line, the br.readLine() method
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my... the inputs given by the user.i had a java program for it and accessed it by creating an object for it.my java code is public class submit { JFrame frame; JTextArea
Display non-duplicate words from file
Display non-duplicate words from file In this tutorial, you will learn how to read a text file and display non-duplicate words in ascending order. The given code reads the file and stored the file text into StringBuffer. The buffer
How to read text file in Servlets
How to read text file in Servlets  ... file in servlets. In this example we will use the input stream to read the text from the disk file. The InputStreamReader class is used to read the file
Read text file in PySpark
Read text file in PySpark - How to read a text file in PySpark? The PySpark...().setAppName("read text file in pyspark") sc = SparkContext(conf=conf... configuration conf = SparkConf().setAppName("read text file in pyspark") sc
I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.
I am creating one jsp page in which I read in a text file, then display that data in tabular format. Now I need to calculate a total.  I am reading the file using BufferedReader, then writing the output like this: String
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access... me the things where i went wrong java servlet program protected void... ServletException, IOException { response.setContentType("text/xml"); FileRead fr
how to read text file in jtable in netbeans7.0
how to read text file in jtable in netbeans7.0  text file... want to displaythe above .txt file in jtable as following format having 3 columns contigID length size and then display sequence like "ATGCGSA..." in text
Read Property file From Jmeter
Read Property file From Jmeter  Hi, I am running web driver script from Jmeter, but while reading property file I am getting "File Not Find Exception". Please tell me how to read ".properties" file from Jmeter
Java read lines from file
Java read lines from file  Any code example related to Java read lines from file? In my project there is requirement of reading the file line by line... to read the whole file in one go. So, in my case reading file line by line is only
How to read the .doc/ .docx file in Java Program
the text from the word file as an array and display the data on word file...How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java
How to read text from - Java Beginners
How to read text from   How to retrieve text from the images... Does we have any function to get text over the images  Hi Friend, We are providing you a code that will set text over an image using javascript
how to read a text file with scanner in java
how to read a text file with scanner in java  Hi, I am looking for the example code in Java for reading text file line by line using the Scanner class. how to read a text file with scanner in java? Thanks   Hi
read text file and store the data in mysql - JDBC
read text file and store the data in mysql  when we store the data in mysql table from text file its store the data from new line to new column. how to store the data in different column from a single line of text file
how to sort the text file and display it in jtable
how to sort the text file and display it in jtable   my text file is: contig00001 length=586 numreads=4... ctgaggactcctcg i want to display the lines started with ">" symbol to be displayed
Java read text file
a text file one line at a time. It can also be used to read large text files... text file in Java?": ADS_TO_REPLACE_3 Example of Read text File Line... reads the number from the file. Here we have used hasNextLine() method to read
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section, you will come to know how to read username, password and port no from the properties file and display the data from the database. Now to load the data from
Search word from text file using Java
How to Search word from text file using Java In this section, we are going to search a word from the text file. For this, we have created a swing button... from the text file. Here is the code: import java.io.*; import
How to read and display password from the console
the input from the console using its readPassword method . Here in this example this sample program it will ask to feed the password. Note when feeding the password it won't echo password but it accept and display later. Code
stand alone program for text file editing
stand alone program for text file editing  steps 1.read a text file origi.txt from a location 2.make a copy of the text file to the same location with name as origi_copy.txt(example) 3.each line of the copy should start from 10
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
Program to read a dynamic file content - Java Beginners
Program to read a dynamic file content  Hi, In a single...", "020209.txt", "030209.txt","040209.txt". In a single file I'll get the datas... the database. Im using MySql Database and a standalone java program. I
Help with opening a text file upon closing a program.
Help with opening a text file upon closing a program.  I need some helping in figuring out something I want to do. I have this program... that file to open whenever the user exits the program. My code so far
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...(); in the below example. the error is "cannot convert from java.sql.Statement..." contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page
read excel file from Java - Java Beginners
read excel file from Java  How we read excel file data with the help of java?  Hi friend, For read more information on Java POI visit to : http://www.roseindia.net/java/poi/ Thanks
read from cmd syntax and open the file
read from cmd syntax and open the file  i have to read the name of the database e.g., "database.txt" file from a cmd syntax and open it: java FindKeys database=db.txt;minjoinrows=integer|all how can i do
read from cmd syntax and open the file
read from cmd syntax and open the file  i have to read the name of the database e.g., "database.txt" file from a cmd syntax and open it: java FindKeys database=db.txt;minjoinrows=integer|all how can i do
how to read the .proprties file from struts - Struts
how to read the .proprties file from struts   errpr is :file not found exception:applicationresource.proprties file {system canot find file path"; How to set the file path.  Hi Friend, It seems that you haven't
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
How to read a line from a doc file
How to read a line from a doc file  How to read a line from a doc file   Hi Friend, To run the following code, you need to download POI... { public static void main(String[] args) { File file = null; WordExtractor
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
stop word removal from text file
stop word removal from text file  i need java source code for stop word removal from a text file
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been assigned a work to read big text file and extract the data and save into database... memory assigned is also a limit. So, we have decided to read the text file line
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data

Ads