免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2629 | 回复: 7
打印 上一主题 下一主题

!!请教大家一个有关JComboBox的问题!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-02 13:25 |只看该作者 |倒序浏览
我想让一个JCombobox变量jcb为不可选状态,一直没找到它的这个属性,请问哪位高手知道怎么设?请帮帮忙,多谢!!

论坛徽章:
0
2 [报告]
发表于 2005-08-02 13:47 |只看该作者

!!请教大家一个有关JComboBox的问题!!

setEditable
public void setEditable(boolean aFlag)Determines whether the JComboBox field is editable. An editable JComboBox allows the user to type into the field or selected an item from the list to initialize the field, after which it can be edited. (The editing affects only the field, the list item remains intact.) A non editable JComboBox displays the selected item in the field, but the selection cannot be modified.

Parameters:
aFlag - a boolean value, where true indicates that the field is editable

论坛徽章:
0
3 [报告]
发表于 2005-08-02 14:52 |只看该作者

!!请教大家一个有关JComboBox的问题!!

这个方法得到的不是我要的那个效果。我再说一下,我想要的是JComboBox变量不可选,而不是不可编辑,这两个完全不同的概念。setEditable(false)只是让它不可编辑而已。同样是可以选择的

论坛徽章:
0
4 [报告]
发表于 2005-08-02 17:11 |只看该作者

!!请教大家一个有关JComboBox的问题!!

哪位高手请帮一下忙!此问题对我来说有些重要。多谢先!!!
rlneo 该用户已被删除
5 [报告]
发表于 2005-08-02 17:20 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
6 [报告]
发表于 2005-08-02 17:29 |只看该作者

!!请教大家一个有关JComboBox的问题!!

看不见和不可选是两回事,我想要能看见有这个选项,但由于条件限制而不能对其它操作,但绝对不能把它设为不可见。这样不合理。

论坛徽章:
0
7 [报告]
发表于 2005-08-03 11:17 |只看该作者

!!请教大家一个有关JComboBox的问题!!


  1. import java.awt.BorderLayout;
  2. import java.awt.Component;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;

  5. import javax.swing.JComboBox;
  6. import javax.swing.JFrame;

  7. public class MyJComboBox {
  8.         JFrame jf = null;

  9.         public MyJComboBox() {
  10.                 jf = new JFrame();
  11.                 jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  12.                 jf.setSize(300, 200);
  13.                 jf.setTitle("My JComboBox");
  14.                 jf.getContentPane().add(getMyCombo(), BorderLayout.NORTH);
  15.         }

  16.         private Component getMyCombo() {
  17.                 final JComboBox jcb = new JComboBox();
  18.                 jcb.addItem("1");
  19.                 jcb.addItem("2");
  20.                 jcb.addItem("3");

  21.                 jcb.setSelectedItem(null); // jcb.setEnabled(false);
  22.                 jcb.addActionListener(new ActionListener() {
  23.                         public void actionPerformed(ActionEvent arg0) {
  24.                                 jcb.setSelectedItem(null);
  25.                         }
  26.                 });

  27.                 return jcb;
  28.         }

  29.         private void test() {
  30.                 jf.show();
  31.         }

  32.         /**
  33.          * @param args
  34.          */
  35.         public static void main(String[] args) {
  36.                 MyJComboBox mjcb = new MyJComboBox();
  37.                 mjcb.test();

  38.         }

  39. }
复制代码


记得以前好象有人问过类似的问题。这个是我能想到的简单方法。如果你希望特殊的UI行为,还是写一个自定义的控件吧。

论坛徽章:
0
8 [报告]
发表于 2005-08-03 12:39 |只看该作者

!!请教大家一个有关JComboBox的问题!!

多谢版主!!多谢!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP