QQ下拉列表怎么写

朗晴 2011-08-15 06:25:53
都知知道Eclipse功能强大,开发出Eclipse软件实数不易,哪位高人知道Eclipse原码?

最近在编写一个即时通信软件,就像QQ聊天软件一样,可被一个下拉列表框给难住了,哪位知道下拉列表框怎么写的,请发代码,感激不尽!(谁知道QQ群下拉列表怎么写,点击我的QQ群能下拉出来一堆群)

因为无法上图,报歉!

...全文
455 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
ws198605 2011-08-23
  • 打赏
  • 举报
回复
学习了
朗晴 2011-08-23
  • 打赏
  • 举报
回复
楼上的代码为什么我运行不了,只能做参考了。
有运行通过的人吗
纠结中成长 2011-08-20
  • 打赏
  • 举报
回复
学习中。。。
Ely 2011-08-20
  • 打赏
  • 举报
回复
这是俺昨天为一个朋友回答的一个用JTree列出盘符的例子,希望能帮上楼主

package com.xcy.test;

import java.io.File;

import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultMutableTreeNode;

public class JTreeTest extends JFrame {
public JTreeTest() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("我的电脑");
FileSystemView sys = FileSystemView.getFileSystemView();
File[] files = File.listRoots();
for (int i = 0; i < files.length; i++) {//测试的时候最好是把这行代码换成 for (int i = 1; i < 2; i++) { i=1在我机子上 是指定D盘
DefaultMutableTreeNode temp = new DefaultMutableTreeNode(sys.getSystemDisplayName(files[i]));
root.add(temp);
bind(temp,files[i].toString());//测试的时候最好是把这行代码换成 bind(temp,"D:\xxx\xxx");指定一个文件夹,否则遍历整个文件系统会非常慢
}
JTree jtree = new JTree(root);
this.add(jtree);
this.setSize(500, 500);
this.setVisible(true);
}

public void bind(DefaultMutableTreeNode node,String path){
File file = new File(path);
File[] files = file.listFiles();
for(int i=0;files!=null && i<files.length;i++){
File tempFile = files[i];
if(tempFile.isDirectory()){
DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(tempFile.getName());
node.add(tempNode);
bind(tempNode,tempFile.getAbsolutePath());
}else{
DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(tempFile.getName());
node.add(tempNode);
}
}
}

public static void main(String[] args) {
new JTreeTest();
}
}
Jan丶X 2011-08-19
  • 打赏
  • 举报
回复
很简单。用JTree就可以实现。
flyingZippo 2011-08-19
  • 打赏
  • 举报
回复
随便看看
朗晴 2011-08-19
  • 打赏
  • 举报
回复
哦,那到底用什么框框才能够做出腾讯一样的下拉列表呢?
liruohan123 2011-08-18
  • 打赏
  • 举报
回复
自己写的,献丑了,希望对楼主有点帮助
package qq.com.client.view;

import java.awt.Dimension;
import java.awt.TextField;
import java.awt.event.*;

import javax.swing.*;

public class Login2 extends JFrame {

public String[] guo = { "中国", "美国", "英国", "日本", "德国", "意大利", "法国" };

private JPanel jp = new JPanel();
private JPanel jp1 = new JPanel();
private JPanel jp2 = new JPanel();
private JPanel jp3 = new JPanel();
private JPanel jp4 = new JPanel();
private JPanel jp5 = new JPanel();
private JPanel jp6 = new JPanel();
private JPanel jp7 = new JPanel();
private JPanel jp8 = new JPanel();
private JPanel jp9 = new JPanel();
private JPanel jp10 = new JPanel();

JLabel a = new JLabel("选择头像");
ImageIcon[] imageIcon = new ImageIcon[7];
JComboBox b = new JComboBox();

JLabel c = new JLabel("昵称");

JTextField d = new JTextField(5);

JLabel e = new JLabel("性别:");
JCheckBox f = new JCheckBox();
JLabel g = new JLabel("男");
JCheckBox h = new JCheckBox();
JLabel i = new JLabel("女");
JLabel j = new JLabel("年龄:");
TextField k = new TextField();

String sb = null;
String bs=null;
JLabel l = new JLabel("所在地区:");
JComboBox m = new JComboBox(guo);

JComboBox n = new JComboBox();
JComboBox o = new JComboBox();

JLabel p = new JLabel("输入密码:");
JTextField q = new JTextField(15);

JLabel r = new JLabel("密码由4-16个字符组成,区分大小写");

JLabel s = new JLabel("确认密码:");
JTextField t = new JTextField(15);

JLabel u = new JLabel("密保问题");
JTextField v = new JTextField(15);

JLabel w = new JLabel("问题答案");
JTextField ww = new JTextField(15);

JLabel x = new JLabel("个性签名");
JTextField y = new JTextField();

JButton z = new JButton("取消");
JButton zz = new JButton("提交");




Box box1 = Box.createHorizontalBox();
Box box2 = Box.createHorizontalBox();
Box box3 = Box.createHorizontalBox();
Box box4 = Box.createHorizontalBox();
Box box5 = Box.createHorizontalBox();
Box box6 = Box.createHorizontalBox();
Box box7 = Box.createHorizontalBox();
Box box8 = Box.createHorizontalBox();
Box box9 = Box.createHorizontalBox();
Box box10 = Box.createHorizontalBox();
Box verbox = Box.createVerticalBox();

public Login2() {

y.setPreferredSize(new Dimension(170, 50));


box1.add(a);
box1.add(Box.createHorizontalStrut(20));
box1.add(b);
box1.add(c);
box1.add(d);

box2.add(e);
box2.add(f);
box2.add(g);
box2.add(h);
box2.add(i);
box2.add(j);
box2.add(k);

box3.add(l);
box3.add(m);
box3.add(n);
box3.add(o);

box4.add(p);
box4.add(q);

box5.add(r);

box6.add(s);
box6.add(t);

box7.add(u);
box7.add(v);

box8.add(w);
box8.add(ww);

box9.add(x);
box9.add(y);

box10.add(z);
box10.add(Box.createHorizontalStrut(40));
box10.add(zz);

jp1.add(box1);
jp2.add(box2);
jp3.add(box3);
jp4.add(box4);
jp5.add(box5);
jp6.add(box6);
jp7.add(box7);
jp8.add(box8);
jp9.add(box9);
jp10.add(box10);

verbox.add(jp1);
verbox.add(jp2);
verbox.add(jp3);
verbox.add(jp4);
verbox.add(jp5);
verbox.add(jp6);
verbox.add(jp7);
verbox.add(jp8);
verbox.add(jp9);
verbox.add(jp10);


n.addItem("请选择省份");
o.addItem("请选择城市");

for (int j = 0; j < 7; j++) {

m.addItem(guo[j]);
}

for (int i = 1; i < 7; i++) {
imageIcon[i] = new ImageIcon("./image/" + (i + 1) + ".jpg");

b.addItem(imageIcon[i]);

}

m.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
sb = (String) m.getSelectedItem();

if (sb.equals("中国")) {
String[] Sheng = { "北京", "上海", "山东", "山西", "广东", "辽宁",
"湖南", "重庆", "四川", "云南", "黑龙江", "吉林", "广西", "内蒙古",
"陕西", };

n.removeAllItems();
for (int i = 0; i < Sheng.length; i++) {
n.addItem(Sheng[i]);
}

n.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
bs = (String) n.getSelectedItem();
if(bs.equals("山东")){
String[] shi ={"济南","青岛","聊城","东营","潍坊","烟台","淄博","济宁","德州","枣庄","滨州","临沂","威海"};
o.removeAllItems();
for(int i=0;i<shi.length;i++){
o.addItem( shi[i]);
}
}
}

} );





} else if (sb.equals("美国")) {
String[] Zhou = { "请选择选择州", " 阿拉巴马州", "阿拉斯加州", "亚利桑那州",
"阿肯色州", "科罗拉多州", "康涅狄格州", "特拉华州", "佛罗里达州", "乔治亚州",
"夏威夷州", "爱达荷州", "伊利诺州", "印地安那州", "爱荷华州", "路易斯安那州",
"缅因州", "马里兰州", "麻萨诸塞州", "明尼苏达州", "内华达州", "新罕布什尔州", };
n.removeAllItems();
for (int i = 0; i < Zhou.length; i++) {
n.addItem(Zhou[i]);
}
}
}
});

this.add(verbox);
this.setTitle("QQ申请");
this.setVisible(true);
this.setBounds(200, 200, 500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
new Login2();
}

}
九条腿咸鱼 2011-08-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 huntor 的回复:]
csdn 每个注册用户都有一个相册,可以上传图片。
[/Quote]
现在是不行的,不信你试试?
朗晴 2011-08-18
  • 打赏
  • 举报
回复
我开发的是JAVA C/S 架构的项目,
请问下拉列表用什么图形编程语言和QQ下拉列表一样
woniu4500 2011-08-18
  • 打赏
  • 举报
回复
用JTree呀,树结构啊。可以自定义群组的图片。不过这个还得优化下。Jtree主要是做管理系统的对界面的优化不是很好。可以说难看。不过费些事。
kaerlandry 2011-08-18
  • 打赏
  • 举报
回复
你的报错能全贴上来吗?
朗晴 2011-08-18
  • 打赏
  • 举报
回复
运行楼上代码报错,如下:
Exception in thread "main" java.lang.Error: Do not use qq.com.client.view.Login2.add
……
请问这是什么错误??
DriftKing 2011-08-17
  • 打赏
  • 举报
回复
TreeView

SWT/JFace
来到我身边 2011-08-17
  • 打赏
  • 举报
回复
如何你开发的是Android项目,可以使用ExpandableListActivity和SimpleExpandableListAdapter
朗晴 2011-08-17
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 lliiqiang 的回复:]
JList渲染
[/Quote]


什么是JList渲染?
luohuijun619 2011-08-16
  • 打赏
  • 举报
回复
朗晴 2011-08-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhouyuqwert 的回复:]
你是说的树结构么 JTree
[/Quote]

谢谢,就是JTree 谁有案例,发个上来
朗晴 2011-08-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 leehomwong 的回复:]
QQ不是用JAVA写的吧。。
[/Quote]

谢谢,就是JTree 谁有案例,发个上来
feifeikub 2011-08-16
  • 打赏
  • 举报
回复
LZ是想用JComboBox还是输入文本形式下拉?JComboBox相对容易,文本下来得要一个插件,网上几乎找不到资料的,我项目中因为也要做一个文本下拉!花了2个多星期才写出了一个插件,是非常的复杂的。
加载更多回复(8)

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧