我试图显示JTable单元格内的HTML文本,但滚动条没有显示出来。下面是我的代码...JTable单元格内的滚动条
public class TableCellTextRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
final JTextPane jtextPane = new JTextPane();
JScrollPane scrollPane = new JScrollPane(jtextPane);
scrollPane.setPreferredSize(new Dimension(350,350));
scrollPane.setVisible(true);
jtextPane.setEditable(false);
jtextPane.setAutoscrolls(true);
jtextPane.setContentType("text/html");
jtextPane.setText(myHtmlText);
jtextPane.setVisible(true);
jtextPane.setPreferredSize(new Dimension(350,350));
//this setViewPort has no effect
scrollPane.setViewportView(jtextPane);
jtextPane.setVisible(true);
scrollPane.setAutoscrolls(true);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
JPanel jpanel = new JPanel();
jpanel.setVisible(true);
jpanel.setPreferredSize(new Dimension(360, 360));
jpanel.add(scrollPane);
return jpanel;
}
}
滚动条出现,但滚动手柄不出现。你能告诉我我错过了什么吗?
表看起来是这样的:
此外,请考虑使用'ListSelectionListener'的[备用方法](http://stackoverflow.com/a/11782366/230513),在[此处](http://stackoverflow.com/a/12306104/230513)中进行说明。 – trashgod