当前位置: 技术问答>java相关
有谁能去掉TextArea控件中 文字后面的闪烁的光标,高手请进!!!答者有分!!!!!!!!!!!!!
来源: 互联网 发布时间:2015-11-11
本文导语: 由于需要,我需要把TextArea中的光标去掉(而不是鼠标),但怎么也没有办法,查源代码也找不到在哪儿写了闪烁光标的代码。 请问高手,应该怎样让光标不显示出来呢? 高分奉上!不够再加!答者有分! ...
由于需要,我需要把TextArea中的光标去掉(而不是鼠标),但怎么也没有办法,查源代码也找不到在哪儿写了闪烁光标的代码。
请问高手,应该怎样让光标不显示出来呢?
高分奉上!不够再加!答者有分!
请问高手,应该怎样让光标不显示出来呢?
高分奉上!不够再加!答者有分!
|
去掉光标,是吧?
1:设为只读;
2:设光标颜色为背景色;
具体参考代码:
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;
interface MyInitScheme {
void initVarient();
void initFace();
}
class MyMenu extends JMenu implements MyInitScheme {
public MyMenu(String text) {
super(text);
initVarient();
initFace();
}
public void initFace() {
setBackground(SystemColor.desktop);
setFont(new Font("Serif", 0, 16));
setForeground(SystemColor.info);
setBorder(BorderFactory.createEtchedBorder());
}
public void initVarient(){};
}
class MyMenuItem extends JMenuItem implements MyInitScheme {
public MyMenuItem(String text) {
super(text);
initVarient();
initFace();
}
public void initFace() {
setBackground(SystemColor.desktop);
setFont(new Font("Serif", 0, 16));
setForeground(SystemColor.info);
setBorder(BorderFactory.createEtchedBorder());
}
public void initVarient(){};
}
class MyButton extends JButton implements MyInitScheme {
public MyButton(String text) {
super(text);
initVarient();
initFace();
}
public void initFace() {
setBackground(SystemColor.desktop);
setFont(new Font("Serif", 0, 16));
setForeground(SystemColor.info);
setBorder(BorderFactory.createEtchedBorder());
}
public void initVarient(){};
}
class MyFrame extends JFrame implements MyInitScheme {
private JMenuBar mnuBar = new JMenuBar();
private JMenu mnuFile = new MyMenu("File");
private JMenuItem mnuFileExit = new MyMenuItem("Exit");
private JMenu mnuHelp = new MyMenu("Help");
private JMenuItem mnuHelpContact = new MyMenuItem("Contact Me");
private JButton btnDefault = new MyButton("Default");
private JButton btnOther = new MyButton("Another");
private JTextArea txt=new JTextArea(30,20);
private JScrollPane scrollPane=new JScrollPane(txt);
private KeyAdapter key=new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
btnDefault.requestFocus();
}
}
};
public void initVarient(){};
public void initFace() {
this.setSize(new Dimension(320, 240));
this.setResizable(false);
this.getContentPane().setLayout(null);
this.getContentPane().setBackground(SystemColor.activeCaption);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mnuBar.setBackground(SystemColor.desktop);
mnuBar.setBorder(BorderFactory.createRaisedBevelBorder());
mnuFile.setMnemonic('F');
mnuFileExit.setMnemonic('x');
mnuFileExit.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
} );
mnuHelp.setMnemonic('H');
mnuHelpContact.setMnemonic('M');
mnuHelpContact.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
try {
Process p=Runtime.getRuntime().exec("C:/Program Files/"
+"Internet Explorer/IExplore.EXE"
+" mailto:zhangjiawang0809@sohu.com");
} catch (Exception ex) {
System.out.println(ex);
}
}
} );
btnDefault.setBounds(new Rectangle(220, 50, 75, 30));
btnDefault.setMnemonic('D');
btnOther.setBounds(new Rectangle(220, 100, 75, 30));
btnOther.setMnemonic('A');
btnOther.addKeyListener(key);
addKeyListener(key);
mnuFile.add(mnuFileExit);
mnuHelp.add(mnuHelpContact);
mnuBar.add(mnuFile);
mnuBar.add(mnuHelp);
// txt.setEditable(false);
txt.setCaretColor(getBackground());//或者使用具体的颜色值
scrollPane.setBounds(new Rectangle(10, 10, 200, 170));
this.setJMenuBar(mnuBar);
this.getRootPane().setDefaultButton(btnDefault);
this.getContentPane().add(btnDefault, null);
this.getContentPane().add(btnOther, null);
getContentPane().add(scrollPane);
}
public MyFrame(String title) {
super(title);
initVarient();
initFace();
show();
btnOther.requestFocus();
}
}
public class MyButtonApp extends JFrame {
public static void main(String[] args) {
JFrame frame=new MyFrame("Test MyButton");
// frame.setExtendedState(Frame.ICONIFIED);
}
}
1:设为只读;
2:设光标颜色为背景色;
具体参考代码:
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;
interface MyInitScheme {
void initVarient();
void initFace();
}
class MyMenu extends JMenu implements MyInitScheme {
public MyMenu(String text) {
super(text);
initVarient();
initFace();
}
public void initFace() {
setBackground(SystemColor.desktop);
setFont(new Font("Serif", 0, 16));
setForeground(SystemColor.info);
setBorder(BorderFactory.createEtchedBorder());
}
public void initVarient(){};
}
class MyMenuItem extends JMenuItem implements MyInitScheme {
public MyMenuItem(String text) {
super(text);
initVarient();
initFace();
}
public void initFace() {
setBackground(SystemColor.desktop);
setFont(new Font("Serif", 0, 16));
setForeground(SystemColor.info);
setBorder(BorderFactory.createEtchedBorder());
}
public void initVarient(){};
}
class MyButton extends JButton implements MyInitScheme {
public MyButton(String text) {
super(text);
initVarient();
initFace();
}
public void initFace() {
setBackground(SystemColor.desktop);
setFont(new Font("Serif", 0, 16));
setForeground(SystemColor.info);
setBorder(BorderFactory.createEtchedBorder());
}
public void initVarient(){};
}
class MyFrame extends JFrame implements MyInitScheme {
private JMenuBar mnuBar = new JMenuBar();
private JMenu mnuFile = new MyMenu("File");
private JMenuItem mnuFileExit = new MyMenuItem("Exit");
private JMenu mnuHelp = new MyMenu("Help");
private JMenuItem mnuHelpContact = new MyMenuItem("Contact Me");
private JButton btnDefault = new MyButton("Default");
private JButton btnOther = new MyButton("Another");
private JTextArea txt=new JTextArea(30,20);
private JScrollPane scrollPane=new JScrollPane(txt);
private KeyAdapter key=new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
btnDefault.requestFocus();
}
}
};
public void initVarient(){};
public void initFace() {
this.setSize(new Dimension(320, 240));
this.setResizable(false);
this.getContentPane().setLayout(null);
this.getContentPane().setBackground(SystemColor.activeCaption);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mnuBar.setBackground(SystemColor.desktop);
mnuBar.setBorder(BorderFactory.createRaisedBevelBorder());
mnuFile.setMnemonic('F');
mnuFileExit.setMnemonic('x');
mnuFileExit.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
} );
mnuHelp.setMnemonic('H');
mnuHelpContact.setMnemonic('M');
mnuHelpContact.addActionListener(new ActionListener () {
public void actionPerformed(ActionEvent e) {
try {
Process p=Runtime.getRuntime().exec("C:/Program Files/"
+"Internet Explorer/IExplore.EXE"
+" mailto:zhangjiawang0809@sohu.com");
} catch (Exception ex) {
System.out.println(ex);
}
}
} );
btnDefault.setBounds(new Rectangle(220, 50, 75, 30));
btnDefault.setMnemonic('D');
btnOther.setBounds(new Rectangle(220, 100, 75, 30));
btnOther.setMnemonic('A');
btnOther.addKeyListener(key);
addKeyListener(key);
mnuFile.add(mnuFileExit);
mnuHelp.add(mnuHelpContact);
mnuBar.add(mnuFile);
mnuBar.add(mnuHelp);
// txt.setEditable(false);
txt.setCaretColor(getBackground());//或者使用具体的颜色值
scrollPane.setBounds(new Rectangle(10, 10, 200, 170));
this.setJMenuBar(mnuBar);
this.getRootPane().setDefaultButton(btnDefault);
this.getContentPane().add(btnDefault, null);
this.getContentPane().add(btnOther, null);
getContentPane().add(scrollPane);
}
public MyFrame(String title) {
super(title);
initVarient();
initFace();
show();
btnOther.requestFocus();
}
}
public class MyButtonApp extends JFrame {
public static void main(String[] args) {
JFrame frame=new MyFrame("Test MyButton");
// frame.setExtendedState(Frame.ICONIFIED);
}
}
|
jTextArea1.setCaret(new DefaultCaret() {
public boolean isVisible() {
return false;
}
});
public boolean isVisible() {
return false;
}
});
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。