就是实现象jbuilder在系统选择jar包时候,那个显示磁盘和文件夹的combo 最好里面也有图片的那种

解决方案 »

  1.   

    import java.awt.Component;
    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;
    }
    }
      

  2.   

    就是象jb那样的,有路径的那种,就在combo中显示出来,可以只显示打开后的路径
      

  3.   

    不常用JBuilder,不清楚你说的是什么样子
    是否像Windwos地址栏那样前面是硬盘或目录的图标,后面是c:\xxx这样的路径?这个路径JComboBox是无法自动获取的,需要你自己写代码实现。