下面列出了javax.swing.JTable#addMouseMotionListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (this.table == null) {
this.table = table;
HyperlinkMouseListener hyperlinkListener = new HyperlinkMouseListener();
table.addMouseMotionListener(hyperlinkListener);
table.addMouseListener(hyperlinkListener);
}
int columnModelIndex = table.getColumnModel().getColumn(column).getModelIndex();
if (!columnModelIndeces.contains(columnModelIndex)) {
columnModelIndeces.add(columnModelIndex);
}
if (value instanceof Link) {
Link link = (Link) value;
setText(link.getDisplayText());
setToolTipText(link.getDescription());
} else {
setText(value != null ? value.toString() : "");
}
setVisited(isCellLinkVisited(value, row, column));
setDrawUnderline(!underlineOnRollover ||
(row == hitRowIndex && column == hitColumnIndex));
if (!isSelected) {
setBackground(rowColors[row % rowColors.length]);
//setForeground(isCellLinkVisited(value, row, column)?
// visitedForeground : foreground);
setForeground(foreground);
setVisitedForeground(visitedForeground);
} else {
setBackground(table.getSelectionBackground());
setForeground(table.getSelectionForeground());
setVisitedForeground(table.getSelectionForeground());
}
//setBorder(hasFocus? focusBorder : noFocusBorder);
//System.out.println("border insets="+getBorder().getBorderInsets(this));
return this;
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (this.table == null) {
this.table = table;
HyperlinkMouseListener hyperlinkListener = new HyperlinkMouseListener();
table.addMouseMotionListener(hyperlinkListener);
table.addMouseListener(hyperlinkListener);
}
int columnModelIndex = table.getColumnModel().getColumn(column).getModelIndex();
if (!columnModelIndeces.contains(columnModelIndex)) {
columnModelIndeces.add(columnModelIndex);
}
if (value instanceof Link) {
Link link = (Link) value;
setText(link.getDisplayText());
setToolTipText(link.getDescription());
} else {
setText(value != null ? value.toString() : "");
}
setVisited(isCellLinkVisited(value, row, column));
setDrawUnderline(!underlineOnRollover ||
(row == hitRowIndex && column == hitColumnIndex));
if (!isSelected) {
setBackground(rowColors[row % rowColors.length]);
//setForeground(isCellLinkVisited(value, row, column)?
// visitedForeground : foreground);
setForeground(foreground);
setVisitedForeground(visitedForeground);
} else {
setBackground(table.getSelectionBackground());
setForeground(table.getSelectionForeground());
setVisitedForeground(table.getSelectionForeground());
}
//setBorder(hasFocus? focusBorder : noFocusBorder);
//System.out.println("border insets="+getBorder().getBorderInsets(this));
return this;
}
public static void install(JTable table) {
TableCellDrag tcellDrag = new TableCellDrag();
table.addMouseListener(tcellDrag);
table.addMouseMotionListener(tcellDrag);
}
public HeaderlessColumnResizer(JTable table) {
this.table = table;
table.addMouseListener(this);
table.addMouseMotionListener(this);
}
public HeaderlessColumnResizer(JTable table) {
this.table = table;
table.addMouseListener(this);
table.addMouseMotionListener(this);
}
public void initUI() {
setLayout(new BorderLayout());
placemarkTable = new JTable(placemarkTableModel);
placemarkTable.setRowSorter(new TableRowSorter<>(placemarkTableModel));
placemarkTable.setName("placemarkTable");
placemarkTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
placemarkTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
placemarkTable.setRowSelectionAllowed(true);
// IMPORTANT: We set ReorderingAllowed=false, because we export the
// table model AS IS to a flat text file.
placemarkTable.getTableHeader().setReorderingAllowed(false);
ToolTipSetter toolTipSetter = new ToolTipSetter();
placemarkTable.addMouseMotionListener(toolTipSetter);
placemarkTable.addMouseListener(toolTipSetter);
placemarkTable.addMouseListener(new PopupListener());
placemarkTable.getSelectionModel().addListSelectionListener(new PlacemarkTableSelectionHandler());
updateTableModel();
final TableColumnModel columnModel = placemarkTable.getColumnModel();
columnModel.addColumnModelListener(new ColumnModelListener());
JScrollPane tableScrollPane = new JScrollPane(placemarkTable);
JPanel mainPane = new JPanel(new BorderLayout(4, 4));
mainPane.add(tableScrollPane, BorderLayout.CENTER);
buttonPane = new PlacemarkManagerButtons(this);
JPanel content = new JPanel(new BorderLayout(4, 4));
content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
content.add(BorderLayout.CENTER, mainPane);
content.add(BorderLayout.EAST, buttonPane);
Component southExtension = getSouthExtension();
if (southExtension != null) {
content.add(BorderLayout.SOUTH, southExtension);
}
content.setPreferredSize(new Dimension(420, 200));
setCurrentView(snapApp.getSelectedProductSceneView());
setProduct(snapApp.getSelectedProduct(VIEW));
snapApp.getSelectionSupport(ProductSceneView.class).addHandler(new ProductSceneViewSelectionChangeHandler());
snapApp.getProductManager().addListener(new ProductRemovedListener());
updateUIState();
add(content, BorderLayout.CENTER);
}
/**
* Enhances a JTable, so it displays tooltips for cells which are cut
* at the right side.
* This feature is useful for tables with no horizontal scrollbar, since
* the user may see full cell's contents when hovering above the row/cell.
* <p/>
* A tooltip is displayed above table, which hides itself whenever the user
* moves mouse out of component or the tooltip or starts editing (if the table
* is cell-editable).
* <p/>
* The tooltip's contents is painted by the configured CellRenderer.
*
* @param table table to enhance
* @return the table; just use as part of new expression.
*/
public static JTable displayExtendedCells(JTable table) {
CellExtensionSupport supp = new CellExtensionSupport(table);
table.addMouseListener(supp);
table.addMouseMotionListener(supp);
table.getSelectionModel().addListSelectionListener(supp);
return table;
}