就是实现象jbuilder在系统选择jar包时候,那个显示磁盘和文件夹的combo 最好里面也有图片的那种
解决方案 »
- 什么是对象类型转换?
- 如何把Date类换成calendar 类取得当前时间
- 求助高手!!!急急急!!!读入一个文本文件,请输出该文件中的最短一行和最长一行(文件行数不定)
- JInternalFrame设置大小?
- java怎么把word中的字体属性读出来啊
- java中如何打印List<Type>中的内容
- 招聘程序员
- 求教java处理pdm文件的问题
- 500分
- IE中如何DISPLAY SWING?请给予执行过的EXAMPLE!谢谢!
- org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask 问题!!!!!!,请看看!
- 關於WindowAdapter--windowClosing的疑惑
import javax.swing.*;
public class Test {
private JFrame frame = null;
private JPanel pane = null;
private JComboBox com = null;
private String[] s = { "111111", "222222", "333333", "444444", "555555" };
public Test() {
frame = new JFrame("Test");
pane = new JPanel();
com = new JComboBox(s);
com.setRenderer(new IconLabel());
pane.add(com);
frame.getContentPane().add(pane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}class IconLabel extends JLabel implements ListCellRenderer {
public IconLabel() {
this.setOpaque(true);
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value != null) {
this.setText(value.toString());
this.setIcon(new ImageIcon("images/mycomputer.png")); //这里可以根据index的值载入不同的Icon
}
if (isSelected) {
this.setBackground(list.getSelectionBackground());
this.setForeground(list.getSelectionForeground());
} else {
this.setBackground(list.getBackground());
this.setForeground(list.getForeground());
}
return this;
}
}
是否像Windwos地址栏那样前面是硬盘或目录的图标,后面是c:\xxx这样的路径?这个路径JComboBox是无法自动获取的,需要你自己写代码实现。