当前位置: 技术问答>java相关
高分 - 如何写一个可以折行的列表框?
来源: 互联网 发布时间:2015-03-19
本文导语: 大家都用过 QQ 吧,QQ 的聊天记录里,用鼠标点都是选中每一次说话的内容,包括时间等信息,所以总的来说,应该是个列表,但是,它的每一个列表项都是多行的,而且行数还不确定,请问,我应该如何实现这样...
大家都用过 QQ 吧,QQ 的聊天记录里,用鼠标点都是选中每一次说话的内容,包括时间等信息,所以总的来说,应该是个列表,但是,它的每一个列表项都是多行的,而且行数还不确定,请问,我应该如何实现这样一个列表框?
请尽量提供源码,或者资料网址。
请尽量提供源码,或者资料网址。
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* @version 1.0 04/26/99
*/
public class CheckListExample2 extends JFrame {
public CheckListExample2() {
super("CheckList Example");
String[] strs = {"swingnthe second line", "home", "basic", "metal", "JList"};
final JList list = new JList( createData(strs) );
list.setCellRenderer(new CheckListRenderer());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setBorder(new EmptyBorder(0,4,0,0));
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int index = list.locationToIndex(e.getPoint());
CheckableItem item = (CheckableItem)list.getModel().getElementAt(index);
item.setSelected(! item.isSelected());
Rectangle rect = list.getCellBounds(index, index);
list.repaint(rect);
}
});
JScrollPane sp = new JScrollPane(list);
final JTextArea textArea = new JTextArea(3,10);
JScrollPane textPanel = new JScrollPane(textArea);
JButton printButton = new JButton("print");
printButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ListModel model = list.getModel();
int n = model.getSize();
for (int i=0;i
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* @version 1.0 04/26/99
*/
public class CheckListExample2 extends JFrame {
public CheckListExample2() {
super("CheckList Example");
String[] strs = {"swingnthe second line", "home", "basic", "metal", "JList"};
final JList list = new JList( createData(strs) );
list.setCellRenderer(new CheckListRenderer());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setBorder(new EmptyBorder(0,4,0,0));
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int index = list.locationToIndex(e.getPoint());
CheckableItem item = (CheckableItem)list.getModel().getElementAt(index);
item.setSelected(! item.isSelected());
Rectangle rect = list.getCellBounds(index, index);
list.repaint(rect);
}
});
JScrollPane sp = new JScrollPane(list);
final JTextArea textArea = new JTextArea(3,10);
JScrollPane textPanel = new JScrollPane(textArea);
JButton printButton = new JButton("print");
printButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ListModel model = list.getModel();
int n = model.getSize();
for (int i=0;i