jfilechooser上有两个text框吗,上面是显示用户选择的文件名,下面是文件选择类型的!
现在需要让上面的text框成为不可编辑状态,请问各位高手应该怎么弄啊
现在需要让上面的text框成为不可编辑状态,请问各位高手应该怎么弄啊
解决方案 »
- java.lang.ArrayIndexOutOfBoundsException
- 帮忙看看这个yield()方法为什么没起作用
- 为什么窗口初始化显示为最小值??
- 我这个窗体类应该怎么样写才正确
- 图书馆管理系统--都来说两句(看在200分的面子上)
- 正在学习java,谁能提供JDBC开发数据库程序的示例和讲解,非常感谢!
- 如何检测socket状态来加以释放
- 有关开发工具的问题???
- 这里有杭州的吗?为什么我在这里还买不到《java版程序员大本营》?
- 请问如何连接到(局域网)210.32.25.1上SqlServer的mytest数据库?
- [求助] 用sax解析xml文件时出错
- 程序代码都存储在哪里呀?内存还是哪里呀?谢啦~~~~~~~~~~
import java.awt.Color;import javax.swing.*;public class TestFileChooserUI {
private static JLabel findLabel(JComponent comp, String s){
JLabel label = null;
if (comp instanceof JLabel) {
if (((JLabel)comp).getText().equals(s)){
label = (JLabel)comp;
}
} else if (comp instanceof JComponent) {
Component[] comps = comp.getComponents();
for (int i=0; i<comps.length; i++) {
if (comps[i] instanceof JComponent) {
label = findLabel((JComponent)comps[i], s);
if (label != null) {
break;
}
}
}
}
return label;
} public static Component getLabelForInChooser(JFileChooser chooser, String key){
java.util.Locale l = chooser.getLocale();
String s = UIManager.getString(key, l);
javax.swing.plaf.FileChooserUI ui = chooser.getUI();
int count = ui.getAccessibleChildrenCount(chooser);
for (int i=0; i<count; i++) {
javax.accessibility.Accessible a =
ui.getAccessibleChild(chooser, i);
JLabel label = findLabel((JComponent)a, s);
if (label != null) {
return label.getLabelFor();
}
}
return null;
}
public static void main(String[] args) {
JFileChooser chooser = new JFileChooser("");
Component comp =
getLabelForInChooser(chooser, "FileChooser.fileNameLabelText");
if (comp instanceof JTextField) {
JTextField field = ((JTextField)comp);
field.setEditable(false); // 随意
// field.setBackground(Color.WHITE);
}
chooser.showOpenDialog(null);
}
}