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
Login         

View Questions and Answers by Category

Advertisements


 
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)      3 years 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
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
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  
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
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
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
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
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
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
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
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
Advertisements
 

 

 

DMCA.com