Results 1 to 4 of 4

Thread: TextComponent class in java

  1. #1
    TorresScott is offline Senior Member
    Join Date
    Dec 2009
    Posts
    239
    Rep Power
    3

    Default TextComponent class in java

    Hi. I am lasted year BCA student. I am learning JAVA programming language. I do not understand how to use TextComponent class. So please provide me any idea about how to use TextComponent class in java language. Thanks in advance.

  2. #2
    EvansMitchell is offline Senior Member
    Join Date
    Dec 2009
    Posts
    227
    Rep Power
    3

    Default

    Code:
    I suggest you to refer following example of ‘TextComponent ', which will give you something idea about the use of this class:
    Code:
    import java.awt.BorderLayout;
    import java.text.MessageFormat;
    
    java.awt.TextComponent
    public class TextDemo {
      	public static void main(String[] arjjgs) throws Exception {
       	 final JTextArea textArea1 = new JTextArea();
        	textArea.setText("text");
        	JScrollPane jScrollPane1 = new JScrollPane(textArea);
        	final MessageFormat header1 = new MessageFormat("My Header");
        	final MessageFormat footer1 = new MessageFormat("My Footer");
        	JPanel contentPane1 = new JPanel();
        	contentPane.setLayout(new BorderLayout());
        	contentPane.add(jScrollPane, BorderLayout.CENTER);
        	JFrame frame1 = new JFrame();
        	frame1.setTitle("Text-component Printing Demo");
        	frame1.setSize(300, 200);
        	frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        	frame1.setContentPane(contentPane);
        	frame1.setVisible(true);
        	textArea.print(header1, footer1, true, null, null, true);
      	}
    }
    **)
    I have tried the given code but it didn’t solve my problem. Please try to provide some other solution.

  3. #3
    RogersNguyen is offline Senior Member
    Join Date
    Dec 2009
    Posts
    227
    Rep Power
    3

    Default

    Following are methods of TextComponent class:

    • setCaretPosition(int pos1)

    • setText(String strg)

    • setSelectionStart(int selectionStrt1)

    • setSelectionEnd(int selectionEnd1)

    • setEditable(boolean bln)

  4. #4
    MorganCooper is offline Senior Member
    Join Date
    Dec 2009
    Posts
    233
    Rep Power
    3

    Default

    The code that I have mentioned will definitely help you. Just try to understand following code. It is very simple code.

    Code:
    import java.awt.*;
    import java.awt.event.*;
    public class TextEntryBox extends java.applet.Applet 
    implements ActionListener { 
        TextArea area;
        TextField field;
        
        public void init() {
            setLayout( new BorderLayout() );
            add( "Center", area = new TextArea() );
            area.setFont( new Font("TimesRoman",Font.BOLD,18) );
            area.setText("Howdy!n");
            add( "South", field = new TextField() );
            field.addActionListener ( this );
        }
        public void actionPerformed(ActionEvent e) {
            area.append( field.getText() + 'n' );
            field.setText("");
        }
    }

Similar Threads

  1. Polygon class in JAVA
    By Shane Robinson in forum Programming
    Replies: 2
    Last Post: 07-04-2010, 06:21 AM
  2. Using MediaTracker class in JAVA
    By MyersGray in forum Programming
    Replies: 2
    Last Post: 04-01-2010, 02:02 PM
  3. FileWriter class in JAVA
    By Theodosia Goodman in forum Programming
    Replies: 2
    Last Post: 03-30-2010, 12:37 PM
  4. TextComponent class in java
    By AllenBrown in forum Programming
    Replies: 2
    Last Post: 03-08-2010, 01:59 PM
  5. JSeparator class of java
    By PerryCollins in forum Programming
    Replies: 2
    Last Post: 02-17-2010, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48