怎么控制java文本框输入法状态。
就是一个JTextField然后光标进去后,不能切换输入法。就是你再怎么切换都没反应。目的就是不能输入汉字。就和QQ2009得账户框一样。各位大侠帮帮忙啦。今天就要用呢。...
就是一个JTextField 然后光标进去后,不能切换输入法。就是你再怎么切换都没反应。目的就是不能输入汉字。就和QQ2009得账户框一样。各位大侠帮帮忙啦。 今天就要用呢。不对应该是现在就要用。过了今天一切都晚了。
展开
3个回答
2013-07-29
展开全部
你可以禁用掉JTextField的输入法,写一个简单的例子 import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JTextFieldInput extends JFrame{
private JTextField txtField;
public JTextFieldInput()
{
init();
setComponentListener();
setJFrameLocation();
this.setVisible(true);
}
private void init()
{
this.setSize(300,300);
Container content=this.getContentPane();
content.setLayout(new FlowLayout());
txtField=new JTextField(10);
txtField.enableInputMethods(false); //禁用掉输入法
content.add(txtField);
}
private void setJFrameLocation()
{
Dimension screenSize=this.getToolkit().getDefaultToolkit().getScreenSize();
Dimension frameSize=this.getSize();
if(frameSize.width>screenSize.width)
frameSize.width=screenSize.width;
if(frameSize.height>screenSize.height)
frameSize.height=screenSize.height;
this.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2);
}
private void setComponentListener()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[]args)
{
new JTextFieldInput();
}
}
import java.awt.*;
import java.awt.event.*;
public class JTextFieldInput extends JFrame{
private JTextField txtField;
public JTextFieldInput()
{
init();
setComponentListener();
setJFrameLocation();
this.setVisible(true);
}
private void init()
{
this.setSize(300,300);
Container content=this.getContentPane();
content.setLayout(new FlowLayout());
txtField=new JTextField(10);
txtField.enableInputMethods(false); //禁用掉输入法
content.add(txtField);
}
private void setJFrameLocation()
{
Dimension screenSize=this.getToolkit().getDefaultToolkit().getScreenSize();
Dimension frameSize=this.getSize();
if(frameSize.width>screenSize.width)
frameSize.width=screenSize.width;
if(frameSize.height>screenSize.height)
frameSize.height=screenSize.height;
this.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2);
}
private void setComponentListener()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[]args)
{
new JTextFieldInput();
}
}
2013-07-29
展开全部
你 只能做到打开与关闭
INPUT TYPE = text STYLE = "ime-mode:active" >
auto Default. IME is not affected. This is the same as not specifying the ime-mode attribute.
active All characters are entered through the IME. Users can still deactivate the IME.
inactive All characters are entered without IME. Users can still activate the IME.
disabled IME is completely disabled. Users cannot activate the IME if the control has focus.
INPUT TYPE = text STYLE = "ime-mode:active" >
auto Default. IME is not affected. This is the same as not specifying the ime-mode attribute.
active All characters are entered through the IME. Users can still deactivate the IME.
inactive All characters are entered without IME. Users can still activate the IME.
disabled IME is completely disabled. Users cannot activate the IME if the control has focus.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-29
展开全部
做个控制代码段 只要输入的不是ASCII码就不显示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询