String[] data = {"<html><font color="+"red"+">one</font></html>","{"<html><font color="+"blue"+">two</font></html>","three","four","five"}
JList list = new JList(data)
这样就可以了
参考。JColorChooser可以用Java Swing里面的颜色选择器:JColorChooser
例子如下:
public class Color extends javax.swing.JFrame {
public Color() {
initComponents()
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jColorChooser1 = new javax.swing.JColorChooser()
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE)
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane())
getContentPane().setLayout(layout)
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jColorChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
)
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jColorChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(46, Short.MAX_VALUE))
)
pack()
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Color().setVisible(true)
}
})
}
// Variables declaration - do not modify
private javax.swing.JColorChooser jColorChooser1
// End of variables declaration
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)