当我在jtable中向下滚动时,我的数据消失了,有人可以建议吗?

时间:2014-06-27 13:03:37

标签: java swing jtable

我已经拍摄了一个jtable,并为其添加了一个模型,并添加了文本区域渲染和编辑器。

Table.setModel(
  JUTableBindingFactory.createAttributeListBinding(
     Binding, Table name, View name, null, null, attributes));

 Table.getColumnModel()
      .getColumn(i)
      .setCellEditor(
         new TextAreaEditor(
           true, true, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
           JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));

 Table.getColumnModel()
      .getColumn(i)
      .setCellRenderer(
         new TextAreaCellRenderer(
           true, true, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
           JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));

 _Table.setRowHeight(100);

此外,我已将桌子排设置为高。

文本区域渲染器类

 public class TextAreaCellRenderer extends JTextArea implements TableCellRenderer
{
private JScrollPane pane;
private boolean _isEditable = false;
private boolean _isEnabled = false;
private int _verticalBarProperyValue = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
private int _horizontalBarProperyValue = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;


public TextAreaCellRenderer()
{
super();
init();
}

 public TextAreaCellRenderer(boolean isEnabled, boolean isEditable, int
             verticalBarProperyValue, int horizontalBarProperyValue)
 {
   super();
_isEditable = isEditable;
_isEnabled = isEnabled;
_verticalBarProperyValue = verticalBarProperyValue;
_horizontalBarProperyValue = horizontalBarProperyValue;
init();
}

private void init()
{
pane = new JScrollPane(this, _verticalBarProperyValue, _horizontalBarProperyValue);
setLineWrap(true);
setWrapStyleWord(true);
setEditable(_isEditable);
setEnabled(_isEnabled);
}


 /**
  * Returns the cell renderer component.
  */
  public Component getTableCellRendererComponent(JTable table, Object value, 
               boolean    isSelected, boolean hasFocus, int row, int column)
  {
setLineWrap(true);
setWrapStyleWord(true);
setText(value != null ? value.toString() : "");
setBackground((isSelected) ? NWSTheme.BLUE_DARK : NWSTheme.WHITE);
setForeground((isSelected) ? NWSTheme.WHITE : NWSTheme.BLACK);
pane.setEnabled(true);
return pane;           
}
 }

编辑器类也很相似,但问题似乎与此无关,我还应该尝试什么?

1 个答案:

答案 0 :(得分:0)

尝试更多地移动水平卷轴,有时我们不会,并给出您所经历的印象。试试至少