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

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

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

JTable.getIntercellSpacing介绍

暂无

代码示例

代码示例来源:origin: ron190/jsql-injection

/**
 *  Get the preferred width for the specified cell
 */
private int getCellDataWidth(int row, int column) {
  //  Inovke the renderer for the cell to calculate the preferred width
  TableCellRenderer cellRenderer = this.tableAdjust.getCellRenderer(row, column);
  Component c = this.tableAdjust.prepareRenderer(cellRenderer, row, column);
  return c.getPreferredSize().width + this.tableAdjust.getIntercellSpacing().width;
}

代码示例来源:origin: stackoverflow.com

JTable table = new JTable( ... );
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

for (int column = 0; column < table.getColumnCount(); column++)
{
  TableColumn tableColumn = table.getColumnModel().getColumn(column);
  int preferredWidth = tableColumn.getMinWidth();
  int maxWidth = tableColumn.getMaxWidth();

  for (int row = 0; row < table.getRowCount(); row++)
  {
    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(cellRenderer, row, column);
    int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
    preferredWidth = Math.max(preferredWidth, width);

    //  We've exceeded the maximum width, no need to check other rows

    if (preferredWidth >= maxWidth)
    {
      preferredWidth = maxWidth;
      break;
    }
  }

  tableColumn.setPreferredWidth( preferredWidth );
}

代码示例来源:origin: AndreasFagschlunger/O2Xfs

private int getHeaderWidth(final TableCellRenderer renderer,
    final Object value, final int column) {
  final Component c = renderer.getTableCellRendererComponent(table,
      value, false, false, -1, column);
  final int space = table.getIntercellSpacing().width * 2;
  final int width = c.getPreferredSize().width + space;
  return width;
}

代码示例来源:origin: stackoverflow.com

public Dimension getSize(JTable table) {
 Component comp = renderer.getTableCellRendererComponent(
   table, getHeaderValue(), false, false,-1, -1);
 int height = comp.getPreferredSize().height; 
 int width  = 0;
 Enumeration e = v.elements();
 int testNum = 0;
 while (e.hasMoreElements()) {
  Object obj = e.nextElement();
  if (obj instanceof TableColumn) {
   TableColumn aColumn = (TableColumn)obj;
   width += aColumn.getWidth()-table.getIntercellSpacing().width;
   width += margin;
  } else {
   width += ((ColumnGroup)obj).getSize(table).width-table.getIntercellSpacing().width;
  }
 }
 return new Dimension(width+2*table.getIntercellSpacing().width, height);
}

代码示例来源:origin: kaikramer/keystore-explorer

private int getCellDataWidth(int row, int column) {
  // Inovke the renderer for the cell to calculate the preferred width
  TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
  Component c = table.prepareRenderer(cellRenderer, row, column);
  return c.getPreferredSize().width + table.getIntercellSpacing().width;
}

代码示例来源:origin: SKCraft/Launcher

private int getCellDataWidth(int row, int column) {
  //  Inovke the renderer for the cell to calculate the preferred width
  TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
  Component c = table.prepareRenderer(cellRenderer, row, column);
  int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
  return width;
}

代码示例来源:origin: net.sf.kerner-utils/kerner-utils

private int getCellDataWidth(final int row, final int column) {
  // Inovke the renderer for the cell to calculate the preferred width
  final TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
  final Component c = table.prepareRenderer(cellRenderer, row, column);
  final int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
  return width;
}

代码示例来源:origin: AndreasFagschlunger/O2Xfs

private int getWidth(final int row, int column) {
  final TableCellRenderer renderer = table.getCellRenderer(row, column);
  final Component c = table.prepareRenderer(renderer, row, column);
  final int space = table.getIntercellSpacing().width * 2;
  final int width = c.getPreferredSize().width + space;
  return width;
}

代码示例来源:origin: bspkrs/MCPMappingViewer

private int getCellDataWidth(int row, int column)
{
  //  Inovke the renderer for the cell to calculate the preferred width
  TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
  Component c = table.prepareRenderer(cellRenderer, row, column);
  int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
  return width;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-sun-appsrv

private int initColumnSizes() {
int totWidth = tab.getIntercellSpacing().width * model.getColumnCount();
  for (int i = 0; i < model.getColumnCount(); i++) {
    TableColumn column = tab.getColumnModel().getColumn(i);
    Component comp = column.getHeaderRenderer().
             getTableCellRendererComponent(
               null, column.getHeaderValue(), 
               false, false, 0, 0);
  /* 
   * Note the +6 is so that there will be some "white" space
   * on each side of the text in the header.
   */
    int headerWidth = comp.getPreferredSize().width + 6;
    int cellWidth = maxSize(i);
  totWidth += Math.max (headerWidth, cellWidth);
    column.setPreferredWidth(Math.max(headerWidth, cellWidth));
  }
return totWidth;
}

代码示例来源:origin: neueda/jetbrains-plugin-graph-database-support

public void resize() {
  int cols = table.getColumnCount();
  int rows = table.getRowCount();
  int margin = Math.max(table.getIntercellSpacing().width, minMargin);
  TableColumnModel model = table.getColumnModel();
  for (int c = 0; c < cols; c++) {
    TableColumn col = model.getColumn(c);
    String header = String.valueOf(col.getHeaderValue());
    int minWidth = strWidth(header) + margin;
    for (int r = 0; r < rows; r++) {
      TableCellRenderer render = table.getCellRenderer(r, c);
      Component component = table.prepareRenderer(render, r, c);
      int rendererWidth = component.getPreferredSize().width;
      int cellWidth = Math.max(rendererWidth + margin, 1);
      minWidth = Math.max(minWidth, cellWidth);
      if (maxWidth != null && minWidth >= maxWidth) {
        col.setPreferredWidth(maxWidth);
        break;
      }
      col.setPreferredWidth(minWidth);
    }
  }
}

代码示例来源: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: otros-systems/otroslogviewer

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
 String abbreviatePackage = "";
 if (value != null) {
  final ClassWrapper classWrapper = (ClassWrapper) value;
  final String className = Optional.ofNullable(classWrapper.getClassName()).orElse("");
  abbreviatePackage = abbreviatePackageUsingMappings(className, replacements);
  int availableWidth = table.getColumnModel().getColumn(column).getWidth();
  availableWidth -= table.getIntercellSpacing().getWidth();
  if (label.getBorder() != null) {
   Insets borderInsets = label.getBorder().getBorderInsets(label);
   availableWidth -= (borderInsets.left + borderInsets.right);
  }
  FontMetrics fm = label.getFontMetrics(label.getFont());
  abbreviatePackage = abbreviatePackagesToSingleLetter(abbreviatePackage, availableWidth, fm);
  while (fm.stringWidth(abbreviatePackage) > availableWidth && abbreviatePackage.length() > 0) {
   abbreviatePackage = abbreviatePackage.substring(1);
  }
 }
 label.setText(abbreviatePackage);
 return label;
}

代码示例来源:origin: stackoverflow.com

JTable table = new JTable( ... );
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

for (int column = 0; column < table.getColumnCount(); column++)
{
  TableColumn tableColumn = table.getColumnModel().getColumn(column);
  int preferredWidth = tableColumn.getMinWidth();
  int maxWidth = tableColumn.getMaxWidth();

  for (int row = 0; row < table.getRowCount(); row++)
  {
    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(cellRenderer, row, column);
    int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
    preferredWidth = Math.max(preferredWidth, width);

    //  We've exceeded the maximum width, no need to check other rows

    if (preferredWidth >= maxWidth)
    {
      preferredWidth = maxWidth;
      break;
    }
  }

  tableColumn.setPreferredWidth( preferredWidth );
}

代码示例来源:origin: stackoverflow.com

JTable table = new JTable( ... );
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

for (int column = 0; column < table.getColumnCount(); column++)
{
  TableColumn tableColumn = table.getColumnModel().getColumn(column);
  int preferredWidth = tableColumn.getMinWidth();
  int maxWidth = tableColumn.getMaxWidth();

  for (int row = 0; row < table.getRowCount(); row++)
  {
    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(cellRenderer, row, column);
    int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
    preferredWidth = Math.max(preferredWidth, width);

    //  We've exceeded the maximum width, no need to check other rows

    if (preferredWidth >= maxWidth)
    {
      preferredWidth = maxWidth;
      break;
    }
  }

  tableColumn.setPreferredWidth( preferredWidth );
}

代码示例来源:origin: stackoverflow.com

JTable table = new JTable( ... );
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

for (int column = 0; column < table.getColumnCount(); column++)
{
  TableColumn tableColumn = table.getColumnModel().getColumn(column);
  int preferredWidth = tableColumn.getMinWidth();
  int maxWidth = tableColumn.getMaxWidth();

  for (int row = 0; row < table.getRowCount(); row++)
  {
    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(cellRenderer, row, column);
    int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
    preferredWidth = Math.max(preferredWidth, width);

    //  We've exceeded the maximum width, no need to check other rows

    if (preferredWidth >= maxWidth)
    {
      preferredWidth = maxWidth;
      break;
    }
  }

  tableColumn.setPreferredWidth( preferredWidth );
}

代码示例来源:origin: girtel/Net2Plan

@Override
public void mouseClicked(MouseEvent e) {
  e.consume();
  if (e.getClickCount() == 2) {
    JTableHeader header = (JTableHeader) e.getSource();
    TableColumn tableColumn = getResizingColumn(header, e.getPoint());
    if (tableColumn == null) return;
    int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
    JTable table = header.getTable();
    int rowCount = table.getRowCount();
    int width = (int) header.getDefaultRenderer().getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col).getPreferredSize().getWidth();
    for (int row = 0; row < rowCount; 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);
    }
    header.setResizingColumn(tableColumn); /* this line is very important */
    tableColumn.setWidth(width + table.getIntercellSpacing().width);
  }
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-common

public void mouseClicked(final MouseEvent _e){
  if(_e.getClickCount()!=2) {
   return;
  }
  final JTableHeader header = (JTableHeader)_e.getSource();
  final TableColumn tableColumn = getResizingColumn(header, _e.getPoint());
  if(tableColumn==null) {
   return;
  }
  final int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
  final JTable table = header.getTable();
  final int rowCount = table.getRowCount();
  int width = (int)header.getDefaultRenderer()
      .getTableCellRendererComponent(table, tableColumn.getIdentifier()
          , false, false, -1, col).getPreferredSize().getWidth();
  for(int row = 0; row<rowCount; row++){
    final int preferedWidth = (int)table.getCellRenderer(row, col).getTableCellRendererComponent(table,
        table.getValueAt(row, col), false, false, row, col).getPreferredSize().getWidth();
    width = Math.max(width, preferedWidth);
  }
  header.setResizingColumn(tableColumn); // this line is very important
  tableColumn.setWidth(width+table.getIntercellSpacing().width);
}

代码示例来源:origin: stackoverflow.com

private int getPreferredHeight(JTextComponent c) {
  Insets insets = c.getInsets();
  View view = c.getUI().getRootView(c).getView(2);
  int preferredHeight = (int)view.getPreferredSpan(View.Y_AXIS);
  return preferredHeight + insets.top + insets.bottom;
} 
private void setMultiLine(JTable table, TableColumn col, int row) {    
  int tableRowHeight = table.getRowHeight();
  col.setCellRenderer(new TextAreaCellRenderer());
  Component c = table.prepareRenderer(col.getCellRenderer(), row, 2);
  if(c instanceof JTextArea) {
     JTextArea a = (JTextArea) c;
     int h = getPreferredHeight(a) +     table.getIntercellSpacing().height;               
     if(h > tableRowHeight) {
       if (tableRowHeight * 3 < h) 
         table.setRowHeight(row, tableRowHeight * 3);
       else
         table.setRowHeight(row, h);
     }
  }       
}

代码示例来源:origin: AndreasFagschlunger/O2Xfs

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
  final Component template = super.getTableCellRendererComponent(table,
      value, isSelected, hasFocus, row, column);
  textArea.setForeground(template.getForeground());
  textArea.setBackground(template.getBackground());
  textArea.setBorder(((JLabel) template).getBorder());
  textArea.setText(String.valueOf(value));
  final TableColumn tableColumn = table.getColumnModel()
      .getColumn(column);
  final View view = textArea.getUI().getRootView(textArea);
  view.setSize(tableColumn.getWidth(), 0);
  final int rowHeight = (int) view.getPreferredSpan(View.Y_AXIS)
      + (table.getIntercellSpacing().height * 2);
  if (table.getRowHeight(row) != rowHeight) {
    table.setRowHeight(row, rowHeight);
  }
  return textArea;
}

相关文章

JTable类方法