本文整理汇总了Java中javax.swing.JTable.getRowCount方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getRowCount方法的具体用法?Java JTable.getRowCount怎么用?Java JTable.getRowCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getRowCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resizeColumnWidth
import javax.swing.JTable; //导入方法依赖的package包/类
public void resizeColumnWidth(JTable table) {
final TableColumnModel columnModel = table.getColumnModel();
for (int column = 0; column < table.getColumnCount(); column++) {
int width = 50; // Min width
for (int row = 0; row < table.getRowCount(); row++) {
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component comp = table.prepareRenderer(renderer, row, column);
width = Math.max(comp.getPreferredSize().width, width);
}
columnModel.getColumn(column).setPreferredWidth(width);
columnModel.getColumn(column).setMinWidth(minColumnWidths[column]);
}
}
示例2: getNextNode
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public T getNextNode (T node) {
T next = null;
if (node != null) {
int index = Arrays.asList(tableModel.getNodes()).indexOf(node);
if (index >= 0) {
JTable table = getTable();
index = table.convertRowIndexToView(index);
if (++index < table.getRowCount()) {
next = tableModel.getNodes()[table.convertRowIndexToModel(index)];
}
}
}
return next;
}
示例3: RowNumberTable
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Constructor to create a new {@link RowNumberTable} instance.
*
* @param contentTable
* the table the {@link RowNumberTable} should be created for
*/
public RowNumberTable(final JTable contentTable) {
this.contentTable = contentTable;
contentTable.addPropertyChangeListener(listener);
setFocusable(false);
setAutoCreateColumnsFromModel(false);
TableColumn column = new TableColumn();
column.setCellRenderer(new RowNumberRenderer());
addColumn(column);
// calculate preferred width dynamically
int rowCount = contentTable.getRowCount();
preferredWidth = 25;
if (rowCount > 0) {
preferredWidth = 15 + 6 * String.valueOf(rowCount).length();
}
getColumnModel().getColumn(0).setPreferredWidth(preferredWidth);
setPreferredScrollableViewportSize(getPreferredSize());
}
示例4: checkforduplicaterow
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* check whether the <code>row</code> present or not
*
* @param table target table
* @param row target row
* @return <code>true</code> if present else <code>false</code>
*/
static boolean checkforduplicaterow(JTable table, Object[] row) {
String value = "", value1 = "";
int cRow = table.getRowCount(), cCol = table.getColumnCount();
for (Object cell : row) {
value1 += cell != null ? cell.toString() : "";
}
for (int i = 0; i < cRow; i++) {
for (int j = 0; j < cCol; j++) {
Object tmp = table.getModel().getValueAt(i, j);
if (j == 4) {
tmp = "NoRun";
}
value += tmp != null ? tmp.toString() : "";
}
if (value.equals(value1)) {
return true;
}
value = "";
}
return false;
}
示例5: packColumn
import javax.swing.JTable; //导入方法依赖的package包/类
private static void packColumn(JTable table, int vColIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width; // Obtém a largura do cabeçalho da coluna
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(
table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width; // Obtém a largura maxima da coluna de dados
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(
table, table.getValueAt(r, vColIndex), false, false, r,
vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
width += 2 * margin; // Configura a largura
col.setPreferredWidth(width);
}
示例6: setSelectedRow
import javax.swing.JTable; //导入方法依赖的package包/类
private void setSelectedRow(JTable table, Object selectedObject, int objectColumn) {
if(table==null || selectedObject==null || objectColumn==-1)return;
//after move to java6 as minimum requirent for nb may consider to replace with JTable::convertRowIndexToModel and back
//current mplementation works with java5
TableModel model = table.getModel();
int rowCount=table.getRowCount();
for(int i=0; i<rowCount; i++) {
if(selectedObject.equals(model.getValueAt(i, objectColumn))) {
table.setRowSelectionInterval(i, i);
table.scrollRectToVisible(table.getCellRect(i, objectColumn, true));
break;
}
}
}
示例7: canImport
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Called to allow drop operations, allow driver drag full range of rows
* except for last (Add driver box).
*/
@Override
public boolean canImport(TransferHandler.TransferSupport support)
{
JTable.DropLocation dl = (JTable.DropLocation)support.getDropLocation();
JTable target = (JTable)support.getComponent();
if (dl.getRow() > target.getRowCount()) return false;
return true;
}
示例8: putTestData
import javax.swing.JTable; //导入方法依赖的package包/类
private void putTestData(JTable table, int row) {
TestCase testCase = (TestCase) table.getModel();
testCase.startGroupEdit();
TestDataDetail td = (TestDataDetail) dropObject;
for (String col : td.getColumnNames()) {
if (row > table.getRowCount() - 1) {
testCase.addNewStep();
}
table.setValueAt(td.getSheetName() + ":" + col, row++, inputColumn);
}
testCase.stopGroupEdit();
}
示例9: addEmptyRow
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void addEmptyRow(JTable jTable){
// --- Get current position in the table model ----
Vector<Number> rowSelected = null;
Vector<Number> newRow = null;
long currKey = 0L;
long newKey = 0L;
float newValue = 0f;
// --- Get the current or the last row ------------
int modelLineSelected = 0;
int modelLineSelectedNew = 0;
int tableRowSelected = 0;
int tableRowSelectedNew = 0;
tableRowSelected = jTable.getSelectedRow();
if (tableRowSelected==-1 || tableRowSelected>=jTable.getRowCount()) {
tableRowSelected = jTable.getRowCount()-1;
}
if (tableModelDataVector.size()==0) {
// --- Create new data series -------
DataSeries newSeries = parentDataModel.createNewDataSeries(parentDataModel.getDefaultSeriesLabel());
ValuePair initialValuePair = parentDataModel.createNewValuePair(0L, newValue);
parentDataModel.getValuePairsFromSeries(newSeries).add(initialValuePair);
parentDataModel.addSeries(newSeries);
} else {
// --- Get current selection --------
modelLineSelected = jTable.convertRowIndexToModel(tableRowSelected);
rowSelected = tableModelDataVector.get(modelLineSelected);
currKey = (Long) rowSelected.get(tableModelDataVector.getKeyColumnIndex());
// --- Find a new key value ---------
newKey = currKey + 1L;
while (tableModelDataVector.getKeyRowVectorTreeMap().get(newKey)!=null) {
newKey = newKey + 1L;
}
// --- Find new index position ------
modelLineSelectedNew = tableModelDataVector.size();
for (int i=0; i < tableModelDataVector.size(); i++) {
Vector<Number> row = tableModelDataVector.get(i);
long key = (Long) row.get(0);
if (key>newKey) {
modelLineSelectedNew = i;
break;
}
}
// --- Add new row data -------------
newRow = new Vector<Number>();
newRow.add(newKey);
for(int i=1; i<getColumnCount(); i++){
newRow.add(newValue);
try {
this.getChartModel().addOrUpdateValuePair(i-1, newKey, newValue);
this.getOntologyModel().addOrUpdateValuePair(i-1, newKey, newValue);
} catch (NoSuchSeriesException e) {
e.printStackTrace();
}
}
// --- Add new row to table model ---
tableModelDataVector.add(modelLineSelectedNew, newRow);
}
fireTableRowsInserted(0, getRowCount()-1);
// --- Set new selection ----------------
tableRowSelectedNew = jTable.convertRowIndexToView(modelLineSelectedNew);
if(tableRowSelectedNew >= 0){
jTable.setRowSelectionInterval(tableRowSelectedNew, tableRowSelectedNew);
jTable.changeSelection(tableRowSelectedNew, 0, false, false);
}
}
示例10: getTableData
import javax.swing.JTable; //导入方法依赖的package包/类
private List<HashMap<String, String>> getTableData(JTable table) {
List<HashMap<String, String>> data = new ArrayList<>();
HashMap<String, String> row;
JtableUtils.removeEmptyRows(table);
int rowCount = table.getRowCount(), i;
for (i = 0; i < rowCount; i++) {
row = new HashMap<>();
Object val = table.getValueAt(i, 1);
row.put("moduleId", (val == null) ? "" : val.toString());
data.add(row);
}
return data;
}
示例11: updateNumPeople
import javax.swing.JTable; //导入方法依赖的package包/类
public void updateNumPeople(JScrollPane j,JTable t,JLabel l,int index){
for(int k = 0 ; k<numPplPerRoom.length ; k++){
numPplPerRoom[k]=0;
}
if(j.isVisible()){
for(int i = 0; i < t.getRowCount();i++){
numPplPerRoom[index] += Integer.parseInt(t.getModel().getValueAt(i, 1).toString());
}
l.setText((String.valueOf(numPplPerRoom[index])));
}
}
示例12: _getText
import javax.swing.JTable; //导入方法依赖的package包/类
@Override public String _getText() {
JTable table = (JTable) getComponent();
int rows = table.getRowCount();
int cols = table.getColumnCount();
JSONArray r = new JSONArray();
for (int i = 0; i < rows; i++) {
JSONArray c = new JSONArray();
for (int j = 0; j < cols; j++) {
c.put(new JTableCellJavaElement(JTableJavaElement.this, i, j)._getText());
}
r.put(c);
}
return r.toString();
}
示例13: moverowdown
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Moves the selected nullRoww one nullRoww DOWN., unless it is the last
* nullRoww
*
* @param table the target tmodel
*/
public static void moverowdown(JTable table) {
int sRow = table.getSelectedRow();
if (sRow < table.getRowCount() - 1 && sRow >= 0) {
((DefaultTableModel) table.getModel()).moveRow(sRow, sRow, sRow + 1);
table.getSelectionModel().setSelectionInterval(sRow + 1, sRow + 1);
}
}
示例14: printDebugData
import javax.swing.JTable; //导入方法依赖的package包/类
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i = 0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j = 0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}
示例15: getPropertiesFromTable
import javax.swing.JTable; //导入方法依赖的package包/类
public static Properties getPropertiesFromTable(Properties x, JTable table) {
JtableUtils.stopEditing(table);
int rowcount = table.getRowCount();
for (int i = 0; i < rowcount; i++) {
String prop = getString(table.getValueAt(i, 0));
String val = getString(table.getValueAt(i, 1));
if (!prop.isEmpty()) {
x.setProperty(prop, val);
}
}
return x;
}