javax.swing.JTable.getVisibleRect()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中javax.swing.JTable.getVisibleRect()方法的一些代码示例,展示了JTable.getVisibleRect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTable.getVisibleRect()方法的具体详情如下:
包路径:javax.swing.JTable
类名称:JTable
方法名:getVisibleRect

JTable.getVisibleRect介绍

暂无

代码示例

代码示例来源:origin: org.orbisgis/orbisgis-view

private boolean isRowVisible(int row) {
  JViewport viewport = tableScrollPane.getViewport();
  return table.getVisibleRect().intersects(table.getCellRect(row, 0, true));
}

代码示例来源:origin: edu.stanford.protege/protege-editor-owl

private void handleScrollpaneViewportChanged() {
  Rectangle tableVisibleRect = resultsTable.getVisibleRect();
  TableColumn categoryColumn = resultsTable.getColumnModel().getColumn(0);
  int columnWidth = categoryColumn.getWidth();
  int rowHeight = resultsTable.getRowHeight() * 2;
  scrollPane.repaint(new Rectangle(tableVisibleRect.x, tableVisibleRect.y, columnWidth, rowHeight));
}

代码示例来源:origin: protegeproject/protege

private void handleScrollpaneViewportChanged() {
  Rectangle tableVisibleRect = resultsTable.getVisibleRect();
  TableColumn categoryColumn = resultsTable.getColumnModel().getColumn(0);
  int columnWidth = categoryColumn.getWidth();
  int rowHeight = resultsTable.getRowHeight() * 2;
  scrollPane.repaint(new Rectangle(tableVisibleRect.x, tableVisibleRect.y, columnWidth, rowHeight));
}

代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl

private void handleScrollpaneViewportChanged() {
  Rectangle tableVisibleRect = resultsTable.getVisibleRect();
  TableColumn categoryColumn = resultsTable.getColumnModel().getColumn(0);
  int columnWidth = categoryColumn.getWidth();
  int rowHeight = resultsTable.getRowHeight() * 2;
  scrollPane.repaint(new Rectangle(tableVisibleRect.x, tableVisibleRect.y, columnWidth, rowHeight));
}

代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    String toRender = "";
    if (model.isFirstRowInCategory(row)) {
      toRender = value.toString();
    }
    else {
      Rectangle previousCellRect = table.getCellRect(row - 1, column, true);
      if (!table.getVisibleRect().intersects(previousCellRect)) {
        toRender = value.toString();
      }
    }
    JLabel label = (JLabel) super.getTableCellRendererComponent(table, toRender, isSelected, hasFocus, row, column);
    label.setHorizontalTextPosition(SwingConstants.RIGHT);
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    if (!isSelected) {
      label.setForeground(Color.GRAY);
    }
    return label;
  }
}

代码示例来源:origin: protegeproject/protege

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    String toRender = "";
    if (model.isFirstRowInCategory(row)) {
      toRender = value.toString();
    }
    else {
      Rectangle previousCellRect = table.getCellRect(row - 1, column, true);
      if (!table.getVisibleRect().intersects(previousCellRect)) {
        toRender = value.toString();
      }
    }
    JLabel label = (JLabel) super.getTableCellRendererComponent(table, toRender, isSelected, hasFocus, row, column);
    label.setHorizontalTextPosition(SwingConstants.RIGHT);
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    if (!isSelected) {
      label.setForeground(Color.GRAY);
    }
    return label;
  }
}

代码示例来源:origin: edu.stanford.protege/protege-editor-owl

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    String toRender = "";
    if (model.isFirstRowInCategory(row)) {
      toRender = value.toString();
    }
    else {
      Rectangle previousCellRect = table.getCellRect(row - 1, column, true);
      if (!table.getVisibleRect().intersects(previousCellRect)) {
        toRender = value.toString();
      }
    }
    JLabel label = (JLabel) super.getTableCellRendererComponent(table, toRender, isSelected, hasFocus, row, column);
    label.setHorizontalTextPosition(SwingConstants.RIGHT);
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    if (!isSelected) {
      label.setForeground(Color.GRAY);
    }
    return label;
  }
}

代码示例来源:origin: nroduit/Weasis

private static int preferredWidth(JTable table, int col) {
  TableColumn tableColumn = table.getColumnModel().getColumn(col);
  int width = (int) table.getTableHeader().getDefaultRenderer()
    .getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col).getPreferredSize()
    .getWidth();
  if (table.getRowCount() != 0) {
    Rectangle rect = table.getVisibleRect();
    int from = table.rowAtPoint(rect.getLocation());
    int to = table.rowAtPoint(new Point((int) rect.getMaxX(), (int) rect.getMaxY())) + 1;
    for (int row = from; row < to; row++) {
      int preferedWidth = (int) table.getCellRenderer(row, col)
        .getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col)
        .getPreferredSize().getWidth();
      width = Math.max(width, preferedWidth);
    }
  }
  return width + table.getIntercellSpacing().width;
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-ui

/**
 * Returns the row index of the last visible row.
 */
public static int getFirstVisibleRowIndex(JTable table) {
  ComponentOrientation or = table.getComponentOrientation();
  Rectangle r = table.getVisibleRect();
  if (!or.isLeftToRight()) {
    r.translate((int) r.getWidth() - 1, 0);
  }
  return table.rowAtPoint(r.getLocation());
}

代码示例来源:origin: omegat-org/omegat

private void splitBead(int[] rows, int col) {
  modified = true;
  panel.table.clearSelection();
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  Rectangle initialRect = panel.table.getVisibleRect();
  model.splitBead(rows);
  panel.table.changeSelection(rows[0], col, false, false);
  panel.table.changeSelection(rows[rows.length - 1], col, false, true);
  ensureSelectionVisible(initialRect);
}

代码示例来源:origin: omegat-org/omegat

private void editRow(int row, int col) {
  String text = panel.table.getValueAt(row, col).toString();
  EditingPanelController splitter = new EditingPanelController(text);
  String newText = splitter.show(SwingUtilities.getWindowAncestor(panel.table));
  if (newText == null || text.equals(newText)) {
    return;
  }
  modified = true;
  Rectangle initialRect = panel.table.getVisibleRect();
  panel.table.clearSelection();
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  model.editRow(row, col, newText);
  panel.table.changeSelection(row, col, false, false);
  ensureSelectionVisible(initialRect);
}

代码示例来源:origin: omegat-org/omegat

private void mergeRows(int[] rows, int col) {
  modified = true;
  Rectangle initialRect = panel.table.getVisibleRect();
  panel.table.clearSelection();
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  List<Integer> realRows = model.realCellsInRowSpan(col, rows);
  int resultRow = model.mergeRows(realRows, col);
  panel.table.changeSelection(resultRow, col, false, false);
  ensureSelectionVisible(initialRect);
}

代码示例来源:origin: omegat-org/omegat

private void moveRows(int[] rows, int col, int trgRow) {
  modified = true;
  Rectangle initialRect = panel.table.getVisibleRect();
  panel.table.clearSelection();
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  List<Integer> realRows = model.realCellsInRowSpan(col, rows);
  int[] resultRows = model.move(realRows, col, trgRow);
  panel.table.changeSelection(resultRows[0], col, false, false);
  panel.table.changeSelection(resultRows[1], col, false, true);
  ensureSelectionVisible(initialRect);
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core

/**
 * @param table {@link JTable}
 * @return number of visible rows
 */
private static int getNumberOfVisibleRows(JTable table) {
  Rectangle vr = table.getVisibleRect();
  int first = table.rowAtPoint(vr.getLocation());
  vr.translate(0, vr.height);
  return table.rowAtPoint(vr.getLocation()) - first;
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-ui

/**
 * Returns the row index of the last visible row.
 */
public static int getLastVisibleRowIndex(JTable table) {
  ComponentOrientation or = table.getComponentOrientation();
  Rectangle r = table.getVisibleRect();
  r.translate(0, (int) r.getHeight() - 1);
  if (or.isLeftToRight()) {
    r.translate((int) r.getWidth() - 1, 0);
    // The next if makes sure that we don't return -1 simply because
    // there is white space at the bottom of the table (ie, the display
    // area is larger than the table)
  }
  if (table.rowAtPoint(r.getLocation()) == -1) {
    if (getFirstVisibleRowIndex(table) == -1) {
      return -1;
    } else {
      return table.getModel().getRowCount() - 1;
    }
  }
  return table.rowAtPoint(r.getLocation());
}

代码示例来源:origin: omegat-org/omegat

private void setStatus(MutableBead.Status status, int... rows) {
  if (rows.length == 0) {
    return;
  }
  modified = true;
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  for (int row : rows) {
    model.setStatusAtRow(row, status);
  }
  int nextBeadRow = model.nextBeadFromRow(rows[rows.length - 1]);
  if (nextBeadRow != -1) {
    int[] cols = panel.table.getSelectedColumns();
    panel.table.changeSelection(nextBeadRow, cols[0], false, false);
    panel.table.changeSelection(nextBeadRow, cols[cols.length - 1], false, true);
    ensureSelectionVisible(panel.table.getVisibleRect());
  }
}

代码示例来源:origin: nroduit/Weasis

int extra = table.getVisibleRect().width - total;
if (extra > 0) {

代码示例来源:origin: omegat-org/omegat

private void splitRow(int row, int col) {
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  if (!model.isEditableColumn(col)) {
    throw new IllegalArgumentException();
  }
  String text = panel.table.getValueAt(row, col).toString();
  String reference = (String) panel.table.getValueAt(row,
      col == BeadTableModel.COL_SRC ? BeadTableModel.COL_TRG : BeadTableModel.COL_SRC);
  SplittingPanelController splitter = new SplittingPanelController(text, reference);
  String[] split = splitter.show(SwingUtilities.getWindowAncestor(panel.table));
  if (split.length == 1) {
    return;
  }
  modified = true;
  Rectangle initialRect = panel.table.getVisibleRect();
  panel.table.clearSelection();
  int[] resultRows = model.splitRow(row, col, split);
  panel.table.changeSelection(resultRows[0], col, false, false);
  panel.table.changeSelection(resultRows[resultRows.length - 1], col, false, true);
  ensureSelectionVisible(initialRect);
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core

/**
 * ensure that a row is visible in the viewport
 * @param rowIndx row index
 */
private void scrollToRowIfNotVisible(int rowIndx) {
  if(table.getParent() instanceof JViewport) {
    Rectangle visibleRect = table.getVisibleRect();
    final int cellIndex = 0;
    Rectangle cellRect = table.getCellRect(rowIndx, cellIndex, false);
    if (visibleRect.y > cellRect.y) {
      table.scrollRectToVisible(cellRect);
    } else {
      Rectangle rect2 = table.getCellRect(rowIndx + getNumberOfVisibleRows(table), cellIndex, true);
      int width = rect2.y - cellRect.y;
      table.scrollRectToVisible(new Rectangle(cellRect.x, cellRect.y, cellRect.width, cellRect.height + width));
    }
  }
}

代码示例来源:origin: omegat-org/omegat

private void slideRows(int[] rows, int col, int offset) {
  modified = true;
  Rectangle initialRect = panel.table.getVisibleRect();
  panel.table.clearSelection();
  BeadTableModel model = (BeadTableModel) panel.table.getModel();
  List<Integer> realRows = model.realCellsInRowSpan(col, rows);
  int[] resultRows = model.slide(realRows, col, offset);
  int selStart = resultRows[0];
  int selEnd = resultRows[1];
  // If we have a multi-cell selection, trim the selection so that the result remains slideable
  if (selStart != selEnd) {
    while (offset < 0 && !model.canMove(selStart, col, true)) {
      selStart++;
    }
    while (offset > 0 && !model.canMove(selEnd, col, false)) {
      selEnd--;
    }
  }
  panel.table.changeSelection(selStart, col, false, false);
  panel.table.changeSelection(selEnd, col, false, true);
  ensureSelectionVisible(initialRect);
}

相关文章

JTable类方法