请教:如何让jDialog也有最小化按钮?另设置一个jTextfield输入长度什么函数? AWT中是这样用的,你看一下swing中能不能这样用TextField = new TextField(20)JTextField = new JTextField(20) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一个不知道第二个可以试试下面的方法import javax.swing.text.PlainDocument;import javax.swing.text.AttributeSet;import javax.swing.text.BadLocationException;textField.setDocument( new PlainDocument() { public void insertString(int offs, String str, AttributeSet a) throws BadLocationException{ if ((getLength() + str.length()) <= 10 ) { super.insertString(offs, str, a); } else { throw new BadLocationException("Insertion exceeds max size ofdocument", offs); } }}); 忘了说了 ((getLength() + str.length()) <= 10 ) 这里的10 是允许的最长的字符数 你的JDialog加个最小化后,不是和JFrame没什么区别了吗?干什么不用JFrame 我也觉得设置一个jTextfield输入长度,只能判断内容长度来限制 DDrddr方法不错,可以的。关于第一个问题,主要是一级一级的弹出画面,也要求一级一级的返回,所以用了Dialog. 1.可以。2.自己作一个类实现JTextField类的所有功能+你自己想实现的功能 1。写个类:class NewDocument extends PlainDocument { public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (this.getLength() == 100) str = ""; super.insertString(offs, str, a); } }2。 jP6TextField.setDocument(new NewDocument()); 限制JOptionPane.showInputDialog()的输入内容 如何设置一个int 型的可变数组 求助,一道算法题,ACM的,TILE TOPOLOGY JSP下如何调用自己的类? FileinputSream 的问题 跪求在JSP中显示在线人数和网站访问量的代码,在线等! 问一个数据库的简单问题 如何知道一个class在那个jar文件中 请问怎样用正则表达式剔除网页上的html标记呢 关于初始化的问题想请问下 关于Locale类型的对象的问题? java应该提供“销毁对象”的方法吧
第二个可以试试下面的方法
import javax.swing.text.PlainDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;textField.setDocument( new PlainDocument() {
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException{
if ((getLength() + str.length()) <= 10 ) {
super.insertString(offs, str, a);
} else {
throw new BadLocationException("Insertion exceeds max size ofdocument", offs);
}
}
});
2.自己作一个类实现JTextField类的所有功能+你自己想实现的功能
{
public void insertString(int offs, String str, AttributeSet a) throws
BadLocationException {
if (this.getLength() == 100)
str = "";
super.insertString(offs, str, a);
} }
2。 jP6TextField.setDocument(new NewDocument());