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

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

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

JTable.getColumnName介绍

暂无

代码示例

代码示例来源:origin: marytts/marytts

public static int getMaxColumnWidth(JTable table, int column) {
  // Set first to column header width as a minimum
  Font font = table.getFont();
  FontMetrics metrics = table.getGraphics().getFontMetrics(font);
  String header = table.getColumnName(column) + "   "; // Whitespace buffer as a crude way (hack)
                              // to account for the rendering context
  Test.output("Column name: " + header);
  // Convert from string length in characters to pixels
  int widest = metrics.stringWidth(header) + (2 * table.getColumnModel().getColumnMargin());
  Test.output("Starting widest value: " + header + " (" + widest + " pixels)");
  // Now go through each row to see if there is a longer value in the column
  int rows = table.getRowCount();
  Test.output("Row count: " + rows);
  for (int index = 0; index < rows; index++) {
    String cellValue = table.getValueAt(index, column).toString();
    int cellWidth = metrics.stringWidth(cellValue) + (2 * table.getColumnModel().getColumnMargin());
    if (cellWidth > widest) {
      widest = cellWidth;
      Test.output("New widest value: " + widest + " pixels");
    }
  }
  return widest;
}

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

public String getColumnName(final int _i) {
 if (column_ == null) {
  return t_.getColumnName(_i);
 }
 return t_.getColumnName(column_[_i]);
}

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

public Object getElementAt(final int _index) {
 return table_.getColumnName(_index);
}

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

private int getColumnByName(JTable table, String name) {
  for (int i = 0; i < table.getColumnCount(); ++i)
    if (table.getColumnName(i).equals(name))
      return i;
  return -1;
}

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

private int getColumnByName(JTable table, String name) {
  for (int i = 0; i < table.getColumnCount(); ++i)
    if (table.getColumnName(i).equals(name))
      return i;
  return -1;
}

代码示例来源:origin: UISpec4J/UISpec4J

public int getColumnIndex(String columnName) {
 for (int columnIndex = 0; columnIndex < jTable.getColumnCount(); columnIndex++) {
  if (jTable.getColumnName(columnIndex).equalsIgnoreCase(columnName)) {
   return columnIndex;
  }
 }
 java.util.List<String> names = new ArrayList<String>();
 for (int columnIndex = 0; columnIndex < jTable.getColumnCount(); columnIndex++) {
  names.add(jTable.getColumnName(columnIndex));
 }
 AssertAdapter.fail("Column '" + columnName + "' not found - actual names: " + names);
 return -1;
}

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

String[] columnNames = {"First Name", "Last Name","Sport","# of Years"};
 Object[][] data = {
     {"Kathy", "Smith", "Snowboarding", "5"},
     {"John", "Doe", "Rowing", "2"},
     {"Sue", "Black", "Knitting", "8"},
     {"Jane", "White", "Speed reading", "10"},
     {"Joe", "Brown", "Pool", "20"}
 };
 JTable table = new JTable(data, columnNames);
 for(int row = 0; row < table.getRowCount(); row++) {
   for(int column = 0; column < table.getColumnCount(); column++) {
     System.out.print(table.getColumnName(column) + ": ");
     System.out.println(table.getValueAt(row, column));
   }
   System.out.println(""); // Add line space
 }

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

/**
 * Set Column size
 */
private void setColumnWidths() {
  int margin = 10;
  int minwidth = 150;
  JTableHeader tableHeader = paramTable.getTableHeader();
  FontMetrics headerFontMetrics = tableHeader.getFontMetrics(tableHeader.getFont());
  for (int i = 0; i < tableModel.getColumnCount(); i++) {
    int headerWidth = headerFontMetrics.stringWidth(paramTable.getColumnName(i));
    int maxWidth = getMaximalRequiredColumnWidth(i, headerWidth);
    paramTable.getColumnModel().getColumn(i).setPreferredWidth(Math.max(maxWidth + margin, minwidth));
  }
}

代码示例来源:origin: UISpec4J/UISpec4J

public String[] getColumnNames() {
 String[] columnNames = new String[jTable.getColumnCount()];
 for (int columnIndex = 0; columnIndex < jTable.getColumnCount(); columnIndex++) {
  columnNames[columnIndex] = jTable.getColumnName(columnIndex);
 }
 return columnNames;
}

代码示例来源:origin: org.vesalainen.dsql/dsql

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
{
  columnName = table.getColumnName(column);
  if (value != null)
  {
    Blob blob = (Blob) value;
    dialog.setBytes(blob.getBytes());
    button.setText(dialog.getContentDescription());
  }
  else
  {
    button.setText(null);
  }
  return button;
}

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

final JTable table = new JTable(tableModel);
 table.getTableHeader().addMouseListener(new MouseAdapter() {
   @Override
   public void mouseClicked(MouseEvent mouseEvent) {
     int selectedHeader = table.convertColumnIndexToModel(table
         .columnAtPoint(mouseEvent.getPoint()));
     table.getColumn(table.getColumnName(selectedHeader))
         .setCellRenderer(new DefaultTableCellRenderer() {
           public void setBackground(Color c) {
             super.setBackground(Color.blue);
           }
         });
   };
 });

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

public int computePreferredWidth(final int _indexInView){
 final  JTable t = getTable();
 final TableColumn c = t.getColumn(t.getColumnName(_indexInView));
 return computePreferredWidth(t, c, _indexInView);
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-runtime-swing

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasfocus, int row, int column) {
  if (column > keys.length) {
    throw new IndexOutOfBoundsException("colum can not be greater than " + keys.length);
  }
  TableColumn col = table.getColumn(table.getColumnName(column));
  int index = col.getModelIndex();
  value = _(keys[index]);
  JComponent rendererComponent = (JComponent) delegate.getTableCellRendererComponent(table, value, isSelected, hasfocus, row, column);
  rendererComponent.setToolTipText(_(tips[index]));
  return rendererComponent;
}

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

int nameColNo = getColumnIndex(table, "Name");
String name = (String)table.getValueAt(rowNo, nameColNo);

private int getColumnIndex (JTable table, String header) {
  for (int i=0; i < table.getColumnCount(); i++) {
    if (table.getColumnName(i).equals(header)) return i;
  }
  return -1;
}

代码示例来源:origin: com.synaptix/SynaptixSwing

public String getAccessibleName() {
  AccessibleContext ac = getCurrentAccessibleContext();
  if (ac != null) {
    String name = ac.getAccessibleName();
    if ((name != null) && (name != "")) { //$NON-NLS-1$
      return ac.getAccessibleName();
    }
  }
  if ((accessibleName != null) && (accessibleName != "")) { //$NON-NLS-1$
    return accessibleName;
  } else {
    return table.getColumnName(column);
  }
}

代码示例来源:origin: GoogleCloudPlatform/google-cloud-intellij

@Test
public void testBucketEditorColumnHeaders() {
 initEditorWithBlobs(directoryBlob);
 JTable bucketTable = editorPanel.getBucketContentTable();
 assertThat(bucketTable.getColumnCount()).isEqualTo(4);
 IntStream.range(0, bucketTable.getColumnCount())
   .forEach(
     colIdx ->
       assertThat(INDEX_TO_COL_NAME.get(colIdx))
         .isEqualTo(bucketTable.getColumnName(colIdx)));
}

代码示例来源:origin: UISpec4J/UISpec4J

public void check() {
  checkHeader();
  try {
   AssertAdapter.assertEquals(expectedHeaders.length, jTable.getColumnCount());
   for (int i = 0; i < expectedHeaders.length; i++) {
    AssertAdapter.assertEquals(expectedHeaders[i], jTable.getColumnName(i));
   }
  }
  catch (Error e) {
   AssertAdapter.assertEquals(ArrayUtils.toString(expectedHeaders), ArrayUtils.toString(getColumnNames()));
   throw e;
  }
 }
};

代码示例来源:origin: UISpec4J/UISpec4J

public void check() {
  checkHeader();
  try {
   AssertAdapter.assertTrue(countHeaderToCheck <= jTable.getColumnCount());
   for (int i = 0; i < expectedHeaders.length; i++) {
    AssertAdapter.assertEquals(expectedHeaders[i], jTable.getColumnName(i));
   }
  }
  catch (Error e) {
   AssertAdapter.assertEquals(ArrayUtils.toString(expectedHeaders), ArrayUtils.toString(getColumnNames()));
   throw e;
  }
 }
};

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

private void selectVisibleColumns() {
  setCurrentWidths();
  String viewName = null;
  if ( getParent() != null )
    viewName = getParent().getName();
  if ( tableModel.selectVisibleColumns( viewName, treeTable.getColumnName(0),
                     getSortedNodeTreeModel ().getRootDescription() ) ) {
    if ( tableModel.getVisibleSortingColumn() == -1 )
      getSortedNodeTreeModel ().setSortedByProperty( null );
    setTreePreferredWidth( treeColumnWidth );
    for (int i=0; i < tableModel.getColumnCount(); i++) {
      setTableColumnPreferredWidth( tableModel.getArrayIndex( i ), tableModel.getVisibleColumnWidth( i ) );
    }
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

private void selectVisibleColumns() {
  setCurrentWidths();
  String viewName = null;
  if ( getParent() != null )
    viewName = getParent().getName();
  if ( tableModel.selectVisibleColumns( viewName, treeTable.getColumnName(0),
                     getSortedNodeTreeModel ().getRootDescription() ) ) {
    if ( tableModel.getVisibleSortingColumn() == -1 )
      getSortedNodeTreeModel ().setSortedByProperty( null );
    setTreePreferredWidth( treeColumnWidth );
    for (int i=0; i < tableModel.getColumnCount(); i++) {
      setTableColumnPreferredWidth( tableModel.getArrayIndex( i ), tableModel.getVisibleColumnWidth( i ) );
    }
  }
}

相关文章

JTable类方法