Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT Program to read the text from a file and display it on a JFrame.

Have Programming Question? Ask it here!
 
 
 


Aman Kulkarni
Program to read the text from a file and display it on a JFrame.
1 Answer(s)      2 years and 2 months ago
Posted in : Swing AWT


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 ?


Advertisement
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
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
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
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 text File
Read text File  Hi,How can I get line and keep in a String in Java
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
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
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 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
Java read text file
by other program. Here we have used DataInputStream class to read the text file... a text file one line at a time. It can also be used to read large text files.... Example of Read text File Line by Line: import java.io.*; class FileRead
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
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 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
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
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 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
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 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
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
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
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 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
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
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
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
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
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 file line by line in Java program
to read a file with name ?Read file line by line in Java.txt? that includes a text...() method is invocated, they can convert the bytes read from the file... required as it can directly reads the number from the file. Example of Read file
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... void main(String[] args) { File file = null; WordExtractor extractor = null
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
Read text file to 2D array and sorting the second column
Read text file to 2D array and sorting the second column  we found that the student names with marks in a text file the marks decreases significantly... their names in a text file
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 read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
Java read file
There are many ways to read a file in Java. DataInputStream class is used to read text File line by line. BufferedReader is also used to read a file in Java... BufferedReader class read text from a character-input stream rather than read one
Removing duplicate white spaces from a text file
duplicate white spaces from a specific text file. In this section a program is given... spaces from the given text file. This program reads the file line-by-line for search... with the single white space. Program Result: This program takes a text file name from which
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
Adding text in to text area of jframe at new line with different background colour
Adding text in to text area of jframe at new line with different background colour  Hi, I am reading text from text file and i want to write that text in to text area of jframe.But i am reading line by line from file and i want
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
Advertisements
 

 

 

DMCA.com