列表都不会怎么得了?跪求:列表组件 跪求列表组件:希望这个组件能像Windows文件浏览器一样能够实现大图标、小图标、列表、详细信息等功能,最好有监听在图标上的单击、双击、右击。用基本组件来实现的方法也可以,谢谢了!E-mail:[email protected],请发邮件给我,谢谢了!如果我搞到了,有需要的请发邮件给我,我会转发给你的!有希望要这个组件的同行记得顶呀,让这个帖子别沉了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 图表什么的我不会,用list组件可以实现列表的基本功能我把list支持的事件列一下以供参考 action focus item key mouse mousemotion希望能给你有帮助 那你有没有已经实现的代码?可不可以发到我邮箱?[email protected] 我本来已经放弃了的.....因为在排版方面我一直解决不了...你看看吧,希望对你有帮助.不过在用之前,请复制一个png图片文件到C:/a.png作为图标.从楼下开始放. import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;public class Chooser extends JPanel implements ItemListener,ActionListener{ protected String add="C:"; protected JComboBox jcb; public Chooser() { String[] disks={"C:/","D:/","E:/","F:/"}; jcb=new JComboBox(disks); jcb.setEditable(true); this.setLayout(new BorderLayout()); JLabel jl=new JLabel("地址"); JButton jb=new JButton("转到"); jb.addActionListener(this); this.add(jl,BorderLayout.WEST); this.add(jcb,BorderLayout.CENTER); this.add(jb,BorderLayout.EAST); jcb.addItemListener(this); } public void setAddress(String add) { this.add=add; jcb.getEditor().setItem(add); } public String getAddress() { return add; } public void itemStateChanged(ItemEvent e) { add=(String)jcb.getModel().getSelectedItem(); MainFrame.hi.setData(add); } public void actionPerformed(ActionEvent e) { MainFrame.hi.setData(add); }} HList.java:import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import java.net.URI;import java.net.URISyntaxException;public class HList extends JPanel implements ActionListener{ File f; String path=null; Vector v=new Vector(); int showStyle=FileItem.BIG_ICON; public HList() { setData("C:/"); } public void setData(String path) { f=new File(path); MainFrame.ci.setAddress(path); this.path=path; this.removeAll(); this.validate(); this.repaint(); File[] temp=f.listFiles(); for(int i=0;i<temp.length;i++) { FileItem temp2=new FileItem(temp[i].getName(),showStyle,temp[i].getAbsolutePath()); temp2.addActionListener(this); this.add(temp2); } this.setSize(400,400); } public void setStyle(int type) { showStyle=type; setData(path); } public void actionPerformed(ActionEvent e) { File f2=new File(((FileItem)e.getSource()).abp); if(f2.isDirectory()) { this.setData(f2.getAbsolutePath()); } else { try { Desktop.getDesktop().browse(new URI(f2.getAbsolutePath().replace('\\', '/'))); } catch (Exception e1) { e1.printStackTrace(); } } }}class FileItem extends JButton{ public static int BIG_ICON=1; public static int LIST_ICON=2; public String abp=null; public FileItem(String name,int listType,String abp) { this.abp=abp; this.setContentAreaFilled(false); if(name.length()>8){ this.setText(name.substring(0,8)); this.setToolTipText(name); } else this.setText(name); //this.setIcon(new ImageIcon(type+listType+".png"));// this.setIcon(new ImageIcon("C:/a.png"));//测试用.实际写的时候,你得准备很多图片 this.setVerticalTextPosition(JLabel.CENTER); this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); } } 这是“hoverlees(好棒)”发给我的短消息,公布如下(希望对你有好处):郁闷啊,帖子不能连续回复三次,最后一个文件我私邮给你吧.希望对你有点帮助.注意,HList.java里用了JDK1.6的Desktop类,如果你是1.5,把那儿去掉就是.import javax.swing.*;import java.awt.*;public class MainFrame extends JFrame{protected Chooser c;protected HList h;public static Chooser ci=null;public static HList hi=null;public MainFrame(){super("试试.呵呵."); c=new Chooser();ci=c;h=new HList();hi=h;JScrollPane jsp=new JScrollPane();jsp.setViewportView(h);this.getContentPane().setLayout(new BorderLayout());this.setSize(Toolkit.getDefaultToolkit().getScreenSize());this.getContentPane().add(c,BorderLayout.NORTH);this.getContentPane().add(jsp,BorderLayout.CENTER);this.setDefaultCloseOperation(3);this.setVisible(true);}public static void main(String[] args){try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch (Exception e) {e.printStackTrace();}new MainFrame();}} 多线程 银行账户问题 Eclipse打成JAR包却无法双击运行 如何过滤查询条件!! 关于设置器和访问器的问题 到底有谁解决了 JfreeChart 的中文模糊的BUG的? java在运行时,只能在命令提示行下运行吗,不能像exe文件双击吗 怎么把STRING转化为INT 高分求解:利用JavaMail发送邮件时,能否做到不通过SMTP邮件服务器转交,直接将邮件发到对方邮箱中. 哥们这是什么情况来着,关于gui小项目-贪吃蛇. 关于java中对象的内存中的分配,新手求助 java中怎么样在另一个线程中更新界面的数据 jdbc
我把list支持的事件列一下以供参考 action focus item key mouse mousemotion
希望能给你有帮助
[email protected]
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class Chooser extends JPanel implements ItemListener,ActionListener
{
protected String add="C:";
protected JComboBox jcb;
public Chooser()
{
String[] disks={"C:/","D:/","E:/","F:/"};
jcb=new JComboBox(disks);
jcb.setEditable(true);
this.setLayout(new BorderLayout());
JLabel jl=new JLabel("地址");
JButton jb=new JButton("转到");
jb.addActionListener(this);
this.add(jl,BorderLayout.WEST);
this.add(jcb,BorderLayout.CENTER);
this.add(jb,BorderLayout.EAST);
jcb.addItemListener(this);
}
public void setAddress(String add)
{
this.add=add;
jcb.getEditor().setItem(add);
}
public String getAddress()
{
return add;
} public void itemStateChanged(ItemEvent e)
{
add=(String)jcb.getModel().getSelectedItem();
MainFrame.hi.setData(add);
}
public void actionPerformed(ActionEvent e) {
MainFrame.hi.setData(add);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.net.URI;
import java.net.URISyntaxException;public class HList extends JPanel implements ActionListener
{
File f;
String path=null;
Vector v=new Vector();
int showStyle=FileItem.BIG_ICON;
public HList()
{
setData("C:/");
}
public void setData(String path)
{
f=new File(path);
MainFrame.ci.setAddress(path);
this.path=path;
this.removeAll();
this.validate();
this.repaint();
File[] temp=f.listFiles();
for(int i=0;i<temp.length;i++)
{
FileItem temp2=new FileItem(temp[i].getName(),showStyle,temp[i].getAbsolutePath());
temp2.addActionListener(this);
this.add(temp2);
}
this.setSize(400,400);
}
public void setStyle(int type)
{
showStyle=type;
setData(path);
}
public void actionPerformed(ActionEvent e)
{
File f2=new File(((FileItem)e.getSource()).abp);
if(f2.isDirectory())
{
this.setData(f2.getAbsolutePath());
}
else
{
try {
Desktop.getDesktop().browse(new URI(f2.getAbsolutePath().replace('\\', '/')));
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}class FileItem extends JButton
{
public static int BIG_ICON=1;
public static int LIST_ICON=2;
public String abp=null;
public FileItem(String name,int listType,String abp)
{
this.abp=abp;
this.setContentAreaFilled(false);
if(name.length()>8){
this.setText(name.substring(0,8));
this.setToolTipText(name);
}
else this.setText(name);
//this.setIcon(new ImageIcon(type+listType+".png"));//
this.setIcon(new ImageIcon("C:/a.png"));//测试用.实际写的时候,你得准备很多图片
this.setVerticalTextPosition(JLabel.CENTER);
this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
}
}
{
protected Chooser c;
protected HList h;
public static Chooser ci=null;
public static HList hi=null;
public MainFrame()
{
super("试试.呵呵.");
c=new Chooser();
ci=c;
h=new HList();
hi=h;
JScrollPane jsp=new JScrollPane();
jsp.setViewportView(h);
this.getContentPane().setLayout(new BorderLayout());
this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
this.getContentPane().add(c,BorderLayout.NORTH);
this.getContentPane().add(jsp,BorderLayout.CENTER);
this.setDefaultCloseOperation(3);
this.setVisible(true);
}
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e)
{
e.printStackTrace();
}
new MainFrame();
}
}