JTextArea.setSelectionStart
JTextArea.setSelectionEnd可以控制光标显示
JTextArea.setSelectionEnd可以控制光标显示
解决方案 »
- 求教 文件读取到最后一行时总是报错。麻烦高手详细解释或更正
- java 模拟栈 需要一个最优算法(在线等)
- 请有看门狗范例
- Exception in thread "main" java.lang.NullPointerException……………………在线等。。。。。。。
- 关于在startup.bat中设置环境变量的问题
- 关于接口的问题,希望各位仁兄帮忙~~~
- 如何获得键盘输入?
- 将JPanel设为透明?!
- 日期表示问题
- JBuider下怎样单步执行代码?就象VB中按F8那样。
- 谁有java类库全面详细的中文说明,比如.chm文件的,请告诉我?
- 如何使用JAVA截获FLASH第1,2桢并存为GIF或BMP格式!(JAVA能实现吗)高手帮忙!!
import java.awt.event.*;
import javax.swing.*;
import java.util.*;public class applettest extends JApplet {
/** Initializes the applet applettest */
public void init() {
initComponents();
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
scrollout = new JScrollPane();
textout = new JTextArea();
scrollin = new JScrollPane();
textin = new JTextArea();
jMenuBar1 = new JMenuBar(); setForeground(new Color(255, 0, 102));
textout.setFont(new Font("宋体", 0, 12));
textout.setLineWrap(true);
scrollout.setViewportView(textout); getContentPane().add(scrollout, BorderLayout.CENTER); textin.setFont(new Font("宋体", 0, 12));
textin.setLineWrap(true);
textin.setRows(3);
textin.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent evt) {
textinKeyPressed(evt);
}
}); scrollin.setViewportView(textin); getContentPane().add(scrollin, BorderLayout.SOUTH); setJMenuBar(jMenuBar1); } private void textinKeyPressed(KeyEvent evt) {
if(evt.getKeyCode() == Event.ENTER){
str = str + textin.getText() + "\n";
textout.append(str);
textin.setText("");
}
}
* applettest.java
*
* Created on 2004年6月24日, 上午10:28
*//**
*
* @author Administrator
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;public class applettest extends JApplet {
/** Initializes the applet applettest */
public void init() {
initComponents();
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
scrollout = new javax.swing.JScrollPane();
textout = new javax.swing.JTextArea();
scrollin = new javax.swing.JScrollPane();
textin = new javax.swing.JTextArea();
jMenuBar1 = new javax.swing.JMenuBar(); setForeground(new java.awt.Color(255, 0, 102));
textout.setFont(new java.awt.Font("宋体", 0, 12));
textout.setLineWrap(true);
scrollout.setViewportView(textout); getContentPane().add(scrollout, java.awt.BorderLayout.CENTER); textin.setFont(new java.awt.Font("宋体", 0, 12));
textin.setLineWrap(true);
textin.setRows(3);
textin.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
textinKeyPressed(evt);
}
}); scrollin.setViewportView(textin); getContentPane().add(scrollin, java.awt.BorderLayout.SOUTH); setJMenuBar(jMenuBar1); } private void textinKeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode() == Event.ENTER){
// Calendar rightNow = Calendar.getInstance();
// textout.append(rightNow.toString());
String str = textin.getText() + "\n";
textout.append(str);
textin.setText("");
}
}
// 变量声明 - 不进行修改
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JScrollPane scrollin;
private javax.swing.JScrollPane scrollout;
private javax.swing.JTextArea textin;
private javax.swing.JTextArea textout;
// 变量声明结束
}
应该用KeyReleased的方法