內工作,利用這兩種細胞渲染器和編輯器,但仍然滾動條不能正常工作 請建議什麼,使其工作的 滾動條完全不滾動條不表細胞
類移動MultiRowCell擴展AbstractCellEditor實現TableCellEditor的,{的TableCellRenderer
private JScrollPane scrollPane;
private JTextArea textArea;
public MultiRowCell() {
textArea = new JTextArea();
textArea.setEditable(true);
scrollPane = new JScrollPane(textArea);
}
@Override
public boolean isCellEditable(EventObject e) {
System.out.println(e);
return true;
}
@Override
public Object getCellEditorValue() {
return textArea.getText();
}
protected void setCellValue(Object value) {
if (value == null) {
textArea.setText(null);
} else {
textArea.setText(value.toString());
}
textArea.setCaretPosition(0);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
setCellValue(value);
return scrollPane;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
setCellValue(value);
return scrollPane;
}
}
//TextTableCellRenderer tr=new TextTableCellRenderer();
//table.getColumnModel().getColumn(1).setCellEditor(tr);
MultiRowCell re=new MultiRowCell();
table.getColumnModel().getColumn(1).setCellRenderer(re);
table.getColumnModel().getColumn(1).setCellEditor(re);
//table.getColumnModel().getColumn(1).setCellRenderer(r);
//table.getColumnModel().getColumn(1).setCellEditor(e);
//table.getColumnModel().getColumn(2).setCellRenderer(r);
//table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
panel.setLayout(new BorderLayout());
panel.add(table, BorderLayout.CENTER);
panel.add(table.getTableHeader(), BorderLayout.NORTH);
return panel;
我認爲您需要採取的第一步是查看[Concepts:Editors and Renderers](https:// docs .oracle.com/javase/tutorial/uiswing/components/table.html#editrender)瞭解一個渲染器實際上是如何實現一個'JTable'(和其他Swing c omponents)使用它們。然後我認爲你需要弄清楚把你的代碼轉換成單元編輯器,並從那個方向使用它 – MadProgrammer
對於[示例](https://stackoverflow.com/questions/9395554/scrollable-cells-in -jtable) – MadProgrammer
Actualy我已經嘗試過,但無法找到出路。能否請您ellaborate這一點。@ MadProgrammer –