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);}}
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);}}