在做GUI界面时想在JList的单元格里加背景图片,背景图片上再加文本显示,并且此文本显示是实时刷新的,被告之要在java中使用html代码,该怎么用啊??

解决方案 »

  1.   

    原来我使用过,你试一试直接把html脚本放入一个字符串,然后调用该字符串
      

  2.   


    import javax.swing.JFrame;
    import javax.swing.JList;public class JListTest extends JFrame {
    private JList list; /**
     * Launch the application
     * 
     * @param args
     */
    public static void main(String args[]) {
    try {
    JListTest frame = new JListTest();
    frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    } /**
     * Create the frame
     */
    public JListTest() {
    super();
    getContentPane().setLayout(null);
    setBounds(100, 100, 500, 375);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    list = new JList(new String[] {
    "<html><font color='red'>Item1</font></html>",
    "<html><font color='yellow'>Item1</font></html>",
    "<html><font color='green'>Item1</font></html>" });
    list.setBounds(37, 94, 150, 125);
    getContentPane().add(list);
    //
    }
    }