当前位置: 技术问答>java相关
送分:JTextArea
来源: 互联网 发布时间:2015-02-05
本文导语: 可否分别获取 JTextArea 自动换行后的每行的字符串??? (自动换行后!!!) try { JTextArea t=new JTextArea(5,8); t.setWrapStyleWord(true); t....
可否分别获取 JTextArea 自动换行后的每行的字符串???
(自动换行后!!!)
try {
JTextArea t=new JTextArea(5,8);
t.setWrapStyleWord(true);
t.setLineWrap(true);
t.setText("1234567890abcdefghijklmnopqrstuvwxyz");
System.out.println("lineCount "+ t.getLineCount()+ " " + t.getColumns());
int start,end;
start=t.getLineStartOffset(0);
end=t.getLineEndOffset(0);
System.out.println("0 line " + t.getText( start,end - start));
start=t.getLineStartOffset(1);
end=t.getLineEndOffset(1);
System.out.println("1 line " + t.getText(start,end - start));
} catch (Exception e) {
System.out.println("err location");
}
--------------------
setColumns(int) 用后无反应??
(自动换行后!!!)
try {
JTextArea t=new JTextArea(5,8);
t.setWrapStyleWord(true);
t.setLineWrap(true);
t.setText("1234567890abcdefghijklmnopqrstuvwxyz");
System.out.println("lineCount "+ t.getLineCount()+ " " + t.getColumns());
int start,end;
start=t.getLineStartOffset(0);
end=t.getLineEndOffset(0);
System.out.println("0 line " + t.getText( start,end - start));
start=t.getLineStartOffset(1);
end=t.getLineEndOffset(1);
System.out.println("1 line " + t.getText(start,end - start));
} catch (Exception e) {
System.out.println("err location");
}
--------------------
setColumns(int) 用后无反应??
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class testframe extends Frame
{
JTextArea t;
public testframe()
{
try {
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setLayout(new FlowLayout());
setBackground(Color.lightGray);
t=new JTextArea(5,8);
t.setWrapStyleWord(true);
t.setLineWrap(true);
t.setText("1234567890abcdefghijklmnopqrstuvwxyz");
add(t);
Button b = new Button("button");
add(b);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p();
}
});
} catch (Exception e) {
System.out.println("err location");
}
}
public void p()
{
try
{
System.out.println("lineCount "+ t.getLineCount()+ " " + t.getColumns());
int start,end;
for (int i = 0; i linelength)
{
System.out.println(t.getText(start, linelength));
start = start + linelength;
}
System.out.println(t.getText(start, end - start));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
testframe f = new testframe();
f.setSize(400, 300);
f.setVisible(true);
}
}
setColumns(int)也有反应的。
import java.awt.event.*;
import javax.swing.*;
public class testframe extends Frame
{
JTextArea t;
public testframe()
{
try {
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setLayout(new FlowLayout());
setBackground(Color.lightGray);
t=new JTextArea(5,8);
t.setWrapStyleWord(true);
t.setLineWrap(true);
t.setText("1234567890abcdefghijklmnopqrstuvwxyz");
add(t);
Button b = new Button("button");
add(b);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p();
}
});
} catch (Exception e) {
System.out.println("err location");
}
}
public void p()
{
try
{
System.out.println("lineCount "+ t.getLineCount()+ " " + t.getColumns());
int start,end;
for (int i = 0; i linelength)
{
System.out.println(t.getText(start, linelength));
start = start + linelength;
}
System.out.println(t.getText(start, end - start));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
testframe f = new testframe();
f.setSize(400, 300);
f.setVisible(true);
}
}
setColumns(int)也有反应的。
|
gz
|
gz
|
gz
|
gz
|
gz
|
up
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。