@Override public void update(Observable o, Object arg) { SortedSet<Feature> fs = model.selectionModel().getFeatureSelection(); if (fs.size() == 1) { if (fs.first().type() == listModel.getType()) { int row = listModel.getRow(fs.first()); // getSelectionModel().setSelectionInterval(row, row); if (!(getParent() instanceof JViewport)) { return; } JViewport viewport = (JViewport) getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = getCellRect(row, 0, true); // The location of the view relative to the table Rectangle viewRect = viewport.getViewRect(); int topVisible = viewport.getViewRect().y; int bottomVisible = viewport.getViewRect().height + topVisible; /* When the cell is visible, don't do anything */ if (rect.y > topVisible && rect.y + rect.height < bottomVisible) { return; } // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0). rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y); // Calculate location of rect if it were at the center of view int centerX = (viewRect.width - rect.width) / 2; int centerY = (viewRect.height - rect.height) / 2; // Fake the location of the cell so that scrollRectToVisible // will move the cell to the center if (rect.x < centerX) { centerX = -centerX; } if (rect.y < centerY) { centerY = -centerY; } rect.translate(centerX, centerY); // Scroll the area into view. viewport.scrollRectToVisible(rect); } } }
public void mouseMoved(MouseEvent evt) { JTableHeader header = (JTableHeader) evt.getSource(); JTable table = header.getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); if (vColIndex != this.index && vColIndex >= 0) { header.setToolTipText(listModel.getColumnName(vColIndex)); } this.index = vColIndex; }
@Override public void actionPerformed(ActionEvent e) { listModel.setType(((TypeCombo) e.getSource()).getTerm()); }