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



Home Answers Viewqa Applet Adding text in to text area of jframe at new line with different background colour

Have Programming Question? Ask it here!
 
 
 


nitin
Adding text in to text area of jframe at new line with different background colour
1 Answer(s)      2 years and 5 months ago
Posted in : Applet


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 to write that text every time at new line in text area with different background colour. it is possible in text area of jframe..?


Advertisement
View Answers

November 30, 2011 at 5:11 PM


import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;

public class TextAreaExample {
    public static void main(String[] args)throws Exception{
        JFrame f = new JFrame("First JTextPane Example");
        f.getContentPane().setLayout(new BorderLayout());

        JTextPane text = new JTextPane();
        Random r = new Random();

        BufferedReader br=new BufferedReader(new FileReader("data.txt"));
        String str=" ";

        StyledDocument doc = text.getStyledDocument();

        Style style = text.addStyle(" ", null);
        while((str=br.readLine())!=null){
            Color randomColor = new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256));
            StyleConstants.setForeground(style, randomColor);
            try { doc.insertString(doc.getLength(), str,style);
            doc.insertString(doc.getLength(), "\n",style);
            }
            catch (Exception e){}
        }
        f.getContentPane().add(text, BorderLayout.CENTER);
        f.setSize(350, 250);
        f.show();
    }
    }


Related Tutorials/Questions & Answers:
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... to write that text every time at new line in text area with different background colour. it is possible in text area of jframe
Text Area
Text Area  how to browse an image in text area instead of giving url of particular image
Advertisements
Write Text To File In New Line.
Write Text To File In New Line. In this tutorial you will learn how to write text into file in a new line. When you are writing in a file you may be required to finish the line and want to write the other text in a new line
How to write file text In New Line
text in new line in Java program. How to write the syntax for this with example. thanks   Hi, For write a new text new line we need bufferedwriter... you went new text in new line. For this we created a new text file named
Text Area in HTML
Text Area in HTML       Text  Area in HTML is used to write unlimited number of text in it. Understand with Example The Tutorial illustrate an example from Text Area
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest... representing numbers of type int, one per line. Can you help
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
Java file new line
Java file new line In this section, you will learn how to write the text in new line of text file. Description of code: The package java.io.* has provide... a text in the file, there are different output streams. Among them
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(); JPanel jp1=new JPanel(); JTextArea t1=new JTextArea(); MegaViewer1() throws
Auto grow Text Area using jQuery plug-in
Auto grow Text Area using jQuery plug-in  Hi sir How can we make a textarea auto grow ? What is the name of the plug-in used for auto grow text area. Please mention code with your reply
new String(text) - Java Beginners
: In this case text will go pool area and this.text refer it. this.text = new String...new String(text)  Please, what is the difference between this.text = text; and this.text = new String(text); in the example: public
spell cheking in text area - JSP-Servlet
spell cheking in text area   Hi Good Morning. I am developing web application. Now i am in one JSP page. in this page i have 1 text area. i want spell check functionality by pressing right click in this text area.but i don't
Change background color of text box - Java Beginners
Change background color of text box  Hi how can i change the background color to red of Javascript text box when ever user enters an incorrect value while on entering a correct value its background color should change green
How to Create Text Area In Java
How to Create Text Area In Java       In this section, you will learn how to create Text Area in Java... and a text area is also created on the panel by using JTextArea class
jframe background color not showing
jframe background color not showing  jframe background color is not showing. please suggest.   Just add the background color to JPanel and then add it to JFrame. For example .. JFrame myFrame = new JFrame(); JPanel
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...("serial") public class AddPage extends JFrame { JDesktopPane pane = new...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Auto grow Text Area using jQuery plug-in
Auto grow Text Area using jQuery plug-in In this section, you will learn how to create a text area which auto grow on increment of the content using jQuery Plug-in. We fixed the height of text area to 70 pixels .The size of the window
Layout text along a line using LineMetrics
Layout text along a line using LineMetrics... to layout text along a line. For this, class LineMetrics is used which layouts the text along a line. The Font class represents the font. The class
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... memory assigned is also a limit. So, we have decided to read the text file line... you kind advice and let's know how to read a large text file line by line in java
Break a Line for text layout
Break a Line for text layout   ... to break a line. To break down the text into lines, the class LineBreakMeasurer... in the constructor of class AttributedString which holds the text. To allows iteration
Java Read Lines from Text File and Output in Reverse order to a Different Text File
by line and output in reverse order to the text area field. Can someone help...Java Read Lines from Text File and Output in Reverse order to a Different Text...[] args) { JFrame window = new FileInput(); window.setSize(600, 400
adding background image - Java Beginners
adding background image  how do i add background image to this code...*; public class sampleProg extends JFrame { JButton button = new JButton ("Result... JLabel ("Laurize Albarracin"); JTextField text = new JTextField
i want validation for one text field and text area,email,combobox, in that email will validte by useing regular expressions?
i want validation for one text field and text area,email,combobox... for one text field and text area,email,combobox, in that email will validte by useing...; Enter Name: <input type="text" name="name" size="30
How to extract the entire line with specific data from a Text in java?
How to extract the entire line with specific data from a Text in java?  Hi, i would like to extract data from text like the following one: [CODE... my prog? i know how to read specific line from text with the lineNumber
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
How to extract a specific line from a text file? - IoC
How to extract a specific line from a text file?  Hi all, i'm trying to write a code that return a specific line from a text file. so my first...){ String line = ""; int lineNo; try { FileReader fr = new FileReader("C
java script to replace words starting and ending with tild(~) symbol in a text area with the word highlighted yellow.
with highlighting text in a text area. I am designing a page to send email. currently.... This is applicable in the subject line and the email body. AS per new...java script to replace words starting and ending with tild(~) symbol in a text
gradient text, text effect, text
to take a new file with black background as here. Write Text: Select Horizontal... How to make a gradient text       We can make many different type of text by the help
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
Replacing a Text Node with a New CDATA Section Node
Replacing a Text Node with a New CDATA Section Node... to replace a Text node with new CDATASection Node in a DOM document. Methods which are used for replacement of the text node in the DOM Document are described
hybrid chart(Stacked Area and Line ) - Swing AWT
different chart stacked area chart and line chart both in a single frame...hybrid chart(Stacked Area and Line )  hello i have a problem... to display hybrid graph (Stacked Area and Line ).combination of stacked area chart
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
How to create a new text file that contains the file names of the copied files in a new directory?  Okay so my question is: How to create a new text file that contains the file names of the copied files in a new directory
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed
While retrieving text from database onto JSP, the alignment of line and paragraphs is not followed  I have stored text database through textarea box. While trying to retrieve the same text from db, the text displayed onto
How to read and compare content of two different text file
Description: In the given example you will see how a two text file's content are compared. The BufferedReader class allow us to read a file. The readLine() method used to read the contents of the specified file.  The way
text field
(String[] args){ JFrame f=new JFrame(); JLabel label1=new JLabel("Name: "); JLabel label2=new JLabel("Address: "); final JTextField text1=new...text field  How to retrieve data from text field   Hi
Text Field in HTML
Text Field in HTML       The Text Field in HTML are one line areas, which enable the user to enter input text. Understand with Example The Tutorial illustrates an example from
iPhone Text Field Border 
adding will select each text field and then go to tools -> attributes Inspector...Text Field Boarder  In this tutorial will learn about the text field Boarder, we can set the boarder of text field by selecting the text field
How to make a cloudy text, cloudy text, text
of you text as I have done here. Take another new file for text. Take a New File: Now take a new file to write text as I have taken here. Setting of the Text: We... How to make a cloudy text      
Text to voice
Text to voice  sample code for text to voice in objective c
Java read 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... that is the first // command line parameter FileInputStream fstream = new FileInputStream
adding some value to new column
adding some value to new column   how to update a column having some value into new column that also have some value i need to add this two value in java using result set we can get all the column data but how to add these value
text limitations
text limitations  to give text limitations, i want to show only 50 words in dat page
Text Editor Extensions
Text Editor Extensions       ETEE is an Eclipse plug-in which extends the Eclipse text editors with some extra capabilities for filtering the text using command line
UIView Image Background
UIView Image Background In this tutorial, we are going to show you how to add image at background in UIView. There are two different ways of adding... Background on UIView Create a new project "View Based application" assign name
text file
text file  Hi can you help me I have to modify the program below so that all the data held in it is stored in an external text file.So there should... at the start of the program from a seperate external text file.Thank you! mport
 

 

 

DMCA.com