[java]代码库
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JListTest
{
public static void main(String[] args){
JFrame jf=new JFrame("列表");
jf.setBounds(300,200,400,400);
Container c=jf.getContentPane();
JPanel jp=new JPanel();
JScrollPane js=new JScrollPane();
js.setPreferredSize(new Dimension(100,100));
DefaultListModel list=new DefaultListModel();
list.addElement("恩施");
list.addElement("宜昌");
list.addElement("荆州");
JList jl=new JList(list);
//设置光标
jl.setCursor(new Cursor(Cursor.HAND_CURSOR));
jl.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(e.getClickCount()==2){
JList jl=(JList)e.getSource();
System.out.println(jl.getSelectedValue());
}
}
});
jl.setLayoutOrientation(JList.HORIZONTAL_WRAP);
c.add(jp);
jp.add(js);
js.setViewportView(jl);
jf.setVisible(true);
}
}
初级程序员
by: 还好不是权来 发表于:2017-11-20 15:18:16 顶(0) | 踩(0) 回复
厉害了
回复评论