replaceRange

J

Jenny

Hi,

Could you tell me why the last line will make the textfield 9 letters?
The original text is "test one".

Thank you a lot.

import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
public class Windows {
public static void main(String[] args) {
JFrame f = new JFrame("hello");
f.setSize(200, 300);
f.setLocation(100, 100);
JTextField user = new JTextField(8);
JTextField password = new JTextField(8);
password.setText("pwd");
user.setText(password.getText());

Font ft = new Font("Times New Roman",Font.ITALIC + Font.BOLD ,20);
password.setFont(ft);
FlowLayout flo = new FlowLayout();
Container pane = f.getContentPane();
pane.setLayout(flo);
pane.add(user);
pane.add(password);
JTextArea a = new JTextArea(3,8);
a.insert("test one",0);
pane.add(a);
f.setVisible(true);
//a.append(" one");
a.replaceRange("two", 4,6);}}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top