1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
JComponent c = new JComponent() {
public void paint(Graphics g) {
boolean selected = table.isRowSelected(row);
Component renderer = table.getCellRenderer(row, column).getTableCellRendererComponent(table, value, selected, true, row, column);
c.setFont(table.getFont());
Rectangle paintBounds = SwingUtilities.convertRectangle(table, bounds, this);
SwingUtilities.paintComponent(g, renderer, this, paintBounds);
if (selected) {
return;
}
g.setColor(Color.WHITE);
((Graphics2D) g).draw(paintBounds);
}
};
/**
*
* @param e
*/
public void mouseEntered(MouseEvent e) {
this.column = this.table.columnAtPoint(e.getPoint());
this.row = this.table.rowAtPoint(e.getPoint());
this.value = (String) this.table.getModel().getValueAt(this.row, this.column);
this.bounds = this.table.getCellRect(this.row, this.column, true);
if (!((DefaultTableCellRenderer) this.table.getCellRenderer(this.row, this.column)).getVisibleRect().contains(this.bounds)) {
if (this.oldGlassPane == null) {
this.oldGlassPane = this.table.getRootPane().getGlassPane();
this.c.setOpaque(false);
this.table.getRootPane().setGlassPane(c);
this.c.setVisible(true);
} else {
this.table.getRootPane().repaint();
}
} else {
resetGlassPane();
}
}
/**
*
* @param e
*/
public void mouseExited(MouseEvent e) {
resetGlassPane();
}
private void resetGlassPane() {
if (this.oldGlassPane != null) {
this.c.setVisible(false);
this.table.getRootPane().setGlassPane(this.oldGlassPane);
this.oldGlassPane = null;
}
} |
Partager