① 在java的Swing中如何实现文本框为只读
应该可以
setEditable(false)为不能编辑,但仍然可以选中内容进行复制等操作
setEnable(false)为不能使用,文本框以反白显示,不可选择文本也不可编辑
② java编程,设置文本框内字符不成功
你好,
showField.setText("");//就是这段代码报错
对于这行代码,错误的惟一原因只能是,showField是null,没有赋值
③ html中如何在定义的一个css类中实现设置文本框为只能读不可编辑
CSS不能定义这个。。。
④ 怎样让JAVA里TextField 文本框 不可编辑且变灰
TextField tf=new TextField();
tf.Text="给文本框来填默认数据";
tf.setEditable(false); //设置是否可自以是可编辑的,为true是可编辑,为false是不可编辑会灰掉建议使用这些控件时先大致熟悉其常规属性和方法,具体可以找JDK帮助文档查
⑤ 怎样让JAVA里TextField 文本框 不可编辑且变灰
参考代码如下
TextFieldtf=newTextField(16);
tf.setBackground(Color.LIGHT_GRAY);//文本框背景设置为亮灰色
//tf.setBackground(newColor(244,244,244));//文本框背景设置为指定的颜色
tf.setEditable(false);//文本框设置为不可编辑
效果图
importjava.awt.*;
importjava.awt.event.*;
{
FrameDemo(){
TextFieldtf=newTextField(16);//初始化文本框
tf.setBackground(Color.LIGHT_GRAY);//文本框背景为亮灰色
//tf.setBackground(newColor(244,244,244));//文本框为指定的颜色
tf.setEditable(false);//文本框不许编辑
Paneljp=newPanel();
jp.add(tf);
add(jp);
//窗口属性的设置
setTitle("窗口");//标题
setSize(242,170);//窗口大小
setLocationRelativeTo(null);//窗口居中
addWindowListener(newWindowAdapter(){//点击关闭窗口时,程序结束
@Override
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
}
publicstaticvoidmain(String[]args){
newFrameDemo().setVisible(true);//创建窗口实例,并让窗口可见
}
}
⑥ 如何使用java脚本让不可编辑的文本框变成可编辑的
改为抄 $("input").removeAttr("disabled");//disabled是属性,不是元素,用removeAttr()可以移除属性 当然你也可以这样用 $("input").attr("disabled",false); 如果要是添加属性的话就可以这样 $("input").attr("disabled",true);
⑦ java中编号文本框为什么显示不可编辑灰色状态,代码有什么错误吗,怎么才能变成可编译的
可以直接调用seteditable(boolean)的方法来设置是否可以编辑状态的。
⑧ java怎么实现文本域只读
不用把Enabled设置false,
只要把editable设为false就可以了
添加一个方法keyReleased事件就可以了,类似
public void jTextField1_keyReleased(KeyEvent e) {
jTextField2.setText(jTextField1.getText());
}
⑨ Java怎么修改文本框TextFiled中的内容
JTextField有一个public void setText(String t)方法可以修改JTextField的内容。下面是一个具体的改变内容的实例,单击change按钮一次改变一次。
{
privateJFrameframe;
privateJButtonbutton;
privateJTextFieldfield;
privatestaticintcount=1;
publicWinTest1()
{
frame=newJFrame();
button=newJButton("change");
button.addActionListener(this);
field=newJTextField("thisisdefaultstring!",40);
frame.add(field);
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setLayout(newFlowLayout());
frame.setVisible(true);
}
publicstaticvoidmain(String[]args)
{
newWinTest1();
}
@Override
publicvoidactionPerformed(ActionEvente)
{
if("change".equals(e.getActionCommand()))
{
field.setText("thisismodifieddefaultString"+count++);
}
}
}
⑩ 为什么我用java程序调出来的文本框上面有❌按了不能关掉该文本框
你试一下下面的,已经改好:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class N19 extends JFrame implements ActionListener {
JButton jb;
JTextArea jta;
public static void main(String[] args) {
// TODO Auto-generated method stub
N19 n=new N19("N19");
}
public N19(String title){
this.setBounds(200, 300, 300, 400);
this.setTitle(title);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jb=new JButton("点我");
jb.setActionCommand("nh");
jta=new JTextArea();
jb.addActionListener(this);
this.add(jb,BorderLayout.NORTH);
this.add(jta,BorderLayout.CENTER);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stu
if(e.getActionCommand().equals("nh"))
{
String input = "你好";
jta.append(input+"\n");
}
}
}
原因是jta是类变量后,构造函数里面就不能是 JTextArea jta=new JTextArea();了
而应该是jta=new JTextArea();