你的位置:首页 > Java教程

[Java教程]javax.swing.JList 设置分割线


public class TestJList extends JFrame {  public TestJList() {    JList list = new JList(new String[] { "cc", "zz", "pp" });    this.add(list);    list.setCellRenderer(new DefaultListCellRenderer() {      public void paintComponent(Graphics g) {        super.paintComponent(g);        g.setColor(Color.red);        g.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);      }    });    this.setTitle("Test JList");    this.pack();    this.setVisible(true);  }  public static void main(String[] args) {    TestJList t = new TestJList();  }}