Java Code Examples for javax.swing.table.TableModel#getRowCount()
The following examples show how to use
javax.swing.table.TableModel#getRowCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableCheckBoxColumn.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 7 votes |
@Override public void mouseClicked(MouseEvent e) { JTableHeader header = (JTableHeader) e.getSource(); JTable table = header.getTable(); TableColumnModel columnModel = table.getColumnModel(); int vci = columnModel.getColumnIndexAtX(e.getX()); int mci = table.convertColumnIndexToModel(vci); if (mci == targetColumnIndex) { if (SwingUtilities.isLeftMouseButton(e)) { TableColumn column = columnModel.getColumn(vci); Object v = column.getHeaderValue(); boolean b = Status.DESELECTED.equals(v); TableModel m = table.getModel(); for (int i = 0; i < m.getRowCount(); i++) { m.setValueAt(b, i, mci); } column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED); } else if (SwingUtilities.isRightMouseButton(e)) { if (popupMenu != null) { popupMenu.show(table, e.getX(), 0); } } } }
Example 2
Source File: SaoHuo.java From xunxian with Apache License 2.0 | 6 votes |
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { if (new Func.Message() .showConfirmDialog("设置宠物壳子所有物品的价格为2铜之内自动买进。<br/>注意:设置后原本配置的数据会都变成2铜<br/>确定要进行快速设置?") == ConfirmationCallback.YES) { int money = 2; SaoHuoFunc saoHuoFunc = new SaoHuoFunc(); TableModel model = (TableModel) Command.JframeSaoHuo.petjTable .getModel(); for (int row = model.getRowCount() - 1; row >= 0; row--) { model.setValueAt(money, row, 2); model.setValueAt(saoHuoFunc.moneyToString(money), row, 1); } saoHuoFunc = null; model = null; } }
Example 3
Source File: HeaderCheckBoxHandler.java From java-swing-tips with MIT License | 6 votes |
@Override public void mouseClicked(MouseEvent e) { JTableHeader header = (JTableHeader) e.getComponent(); JTable tbl = header.getTable(); TableColumnModel columnModel = tbl.getColumnModel(); TableModel m = tbl.getModel(); int vci = columnModel.getColumnIndexAtX(e.getX()); int mci = tbl.convertColumnIndexToModel(vci); if (mci == targetColumnIndex && m.getRowCount() > 0) { TableColumn column = columnModel.getColumn(vci); boolean b = column.getHeaderValue() == Status.DESELECTED; for (int i = 0; i < m.getRowCount(); i++) { m.setValueAt(b, i, mci); } column.setHeaderValue(b ? Status.SELECTED : Status.DESELECTED); // header.repaint(); } }
Example 4
Source File: SaoHuo.java From xunxian with Apache License 2.0 | 6 votes |
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { if (new Func.Message() .showConfirmDialog("设置风物志类所有物品的价格为2铜之内自动买进。<br/>注意:设置后原本配置的数据会都变成2铜<br/>确定要进行快速设置?") == ConfirmationCallback.YES) { int money = 2; SaoHuoFunc saoHuoFunc = new SaoHuoFunc(); TableModel model = (TableModel) Command.JframeSaoHuo.fengWuZhijTable .getModel(); for (int row = model.getRowCount() - 1; row >= 0; row--) { model.setValueAt(money, row, 2); model.setValueAt(saoHuoFunc.moneyToString(money), row, 1); } saoHuoFunc = null; model = null; } }
Example 5
Source File: CsvTableEditorSwing.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
protected Object[][] getTableComponentData(TableModel tableModel, boolean tableModelIsLeading) { boolean fixedHeader = getFileEditorState().getFixedHeaders(); int rowCount = tableModel.getRowCount(); int columnCount = tableModel.getColumnCount(); Object[][] values; if (fixedHeader) { values = new Object[rowCount + 1][]; values[0] = getFixedHeaderValues(); } else { values = new Object[rowCount][]; } for (int row = 0; row < rowCount; ++row) { int valuesRowIndex = row + (fixedHeader ? 1 : 0); int modelRow = tableModelIsLeading ? row : tblEditor.convertRowIndexToModel(row); values[valuesRowIndex] = new Object[columnCount]; for (int column = 0; column < columnCount; ++column) { int modelColumn = tableModelIsLeading ? column : tblEditor.convertColumnIndexToModel(column); values[valuesRowIndex][column] = tableModel.getValueAt(modelRow, modelColumn); } } return values; }
Example 6
Source File: TSVExport.java From ChromeForensics with Apache License 2.0 | 6 votes |
/** * * @param modal * @param saveLoc * @return */ @Override public boolean export(TableModel modal, File saveLoc) { int rowCount = modal.getRowCount(); int colCount = modal.getColumnCount(); try (BufferedWriter writer = Files.newBufferedWriter(saveLoc.toPath(), StandardCharsets.UTF_8)) { for (int col = 0; col < colCount; col++) { writer.write(modal.getColumnName(col)); writer.write("\t"); } writer.newLine(); for (int row = 0; row < rowCount; row++) { for (int col = 0; col < colCount; col++) { writer.write((String) modal.getValueAt(row, col)); writer.write("\t"); } writer.newLine(); } logger.info("Export to TSV successful!"); return true; } catch (IOException ex) { logger.debug("Exception Occured during export to TSV.", ex); } return false; }
Example 7
Source File: TableUtil.java From consulo with Apache License 2.0 | 6 votes |
public static int moveSelectedItemsUp(@Nonnull JTable table) { if (table.isEditing()){ table.getCellEditor().stopCellEditing(); } TableModel model = table.getModel(); ListSelectionModel selectionModel = table.getSelectionModel(); int counter = 0; for(int row = 0; row < model.getRowCount(); row++){ if (selectionModel.isSelectedIndex(row)) { counter++; for (int column = 0; column < model.getColumnCount(); column++) { Object temp = model.getValueAt(row, column); model.setValueAt(model.getValueAt(row - 1, column), row, column); model.setValueAt(temp, row - 1, column); } selectionModel.removeSelectionInterval(row, row); selectionModel.addSelectionInterval(row - 1, row - 1); } } Rectangle cellRect = table.getCellRect(selectionModel.getMinSelectionIndex(), 0, true); if (cellRect != null) { table.scrollRectToVisible(cellRect); } table.repaint(); return counter; }
Example 8
Source File: CategoryPanelStepFilters.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean isChanged() { TableModel filterClassesModel = filterClassesTable.getModel(); Set<String> allFilters = new LinkedHashSet<String>(); Set<String> enabledFilters = new HashSet<String>(); for (int i = 0; i < filterClassesModel.getRowCount(); i++) { boolean isEnabled = (Boolean) filterClassesModel.getValueAt(i, 0); String clazz = (String) filterClassesModel.getValueAt(i, 1); allFilters.add(clazz); if (isEnabled) { enabledFilters.add(clazz); } } Set savedEnabledFilters = (Set) Properties.getDefault().getProperties("debugger"). getProperties("sources").getProperties("class_filters").getCollection("enabled", Collections.EMPTY_SET); Set<String> savedAllFilters = (Set<String>) Properties.getDefault().getProperties("debugger"). getProperties("sources").getProperties("class_filters").getCollection("all", Collections.EMPTY_SET); Properties p = Properties.getDefault().getProperties("debugger.options.JPDA"); return useStepFiltersCheckBox.isSelected() != p.getBoolean("UseStepFilters", true) || filterSyntheticCheckBox.isSelected() != p.getBoolean("FilterSyntheticMethods", true) || filterStaticInitCheckBox.isSelected() != p.getBoolean("FilterStaticInitializers", false) || filterConstructorsCheckBox.isSelected() != p.getBoolean("FilterConstructors", false) || stepThroughFiltersCheckBox.isSelected() != p.getBoolean("StepThroughFilters", false) || !savedAllFilters.equals(allFilters) || !savedEnabledFilters.equals(enabledFilters); }
Example 9
Source File: CategoryPanelStepFilters.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void store() { Properties p = Properties.getDefault().getProperties("debugger.options.JPDA"); p.setBoolean("UseStepFilters", useStepFiltersCheckBox.isSelected()); p.setBoolean("FilterSyntheticMethods", filterSyntheticCheckBox.isSelected()); p.setBoolean("FilterStaticInitializers", filterStaticInitCheckBox.isSelected()); p.setBoolean("FilterConstructors", filterConstructorsCheckBox.isSelected()); TableModel filterClassesModel = filterClassesTable.getModel(); Set<String> allFilters = new LinkedHashSet<String>(); Set<String> enabledFilters = new HashSet<String>(); int n = filterClassesModel.getRowCount(); for (int i = 0; i < n; i++) { boolean isEnabled = (Boolean) filterClassesModel.getValueAt(i, 0); String clazz = (String) filterClassesModel.getValueAt(i, 1); allFilters.add(clazz); if (isEnabled) { enabledFilters.add(clazz); } } Properties.getDefault ().getProperties ("debugger"). getProperties ("sources").getProperties ("class_filters"). setCollection ( "all", allFilters ); Properties.getDefault ().getProperties ("debugger"). getProperties ("sources").getProperties ("class_filters"). setCollection ( "enabled", enabledFilters ); p.setBoolean("StepThroughFilters", stepThroughFiltersCheckBox.isSelected()); }
Example 10
Source File: CSVExporter.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected void writeData(TableModel model, String title, Writer writer, TracerProgressObject progress) throws IOException { int columnsCount = model.getColumnCount(); int rowsCount = model.getRowCount(); for (int c = 0; c < columnsCount; c++) { write(writer, "\"" + model.getColumnName(c) + "\""); // NOI18N if (c < columnsCount - 1) write(writer, DELIMITER); } writeLine(writer); for (int r = 0; r < rowsCount; r++) { for (int c = 0; c < columnsCount; c++) { write(writer, "\"" + model.getValueAt(r, c) + "\""); // NOI18N if (c < columnsCount - 1) write(writer, DELIMITER); } writeLine(writer); if (progress.isFinished()) break; if (step == 1) { progress.addStep(); } else { int currentStep = (int)(r * step); if (currentStep > lastStep) { progress.addStep(); lastStep = currentStep; } } } }
Example 11
Source File: OutlineView.java From netbeans with Apache License 2.0 | 5 votes |
void postReadSettings(Properties p, int index, String propertyPrefix) { TableModel model = getModel(); if (model.getRowCount() > 0 && getModelIndex () > 0) { String myPrefix = propertyPrefix + PROP_PREFIX + Integer.toString(index) + "-"; String shortDescription = p.getProperty(myPrefix + PROP_SHORT_DESCRIPTION, null); if (shortDescription != null) { rowModel.setShortDescription(getModelIndex () - 1, shortDescription); } } }
Example 12
Source File: DataManager.java From iBioSim with Apache License 2.0 | 5 votes |
private static String[][] sortData(TableModel m) { String[][] dat = new String[m.getRowCount()][m.getColumnCount()]; for (int i = 0; i < m.getColumnCount(); i++) { for (int j = 0; j < m.getRowCount(); j++) { dat[j][i] = (String) m.getValueAt(j, i); } } double[] d = new double[m.getRowCount()]; for (int i = 0; i < m.getRowCount(); i++) { try { d[i] = Double.parseDouble(dat[i][0]); } catch (Exception e) { d[i] = 0; } } int i, j; double index; String[] index2; for (i = 1; i < d.length; i++) { index = d[i]; index2 = dat[i]; j = i; while ((j > 0) && d[j - 1] > index) { d[j] = d[j - 1]; dat[j] = dat[j - 1]; j = j - 1; } d[j] = index; dat[j] = index2; } return dat; }
Example 13
Source File: XMLExporter.java From netbeans with Apache License 2.0 | 5 votes |
protected int getSteps(TableModel model) { int steps = model.getRowCount(); if (steps > MAX_STEPS) { step = MAX_STEPS / (float)steps; steps = MAX_STEPS; } return steps; }
Example 14
Source File: MailProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private static void processRecipients( final MailDefinition definition, final MimeMessage message, final DataFactory dataFactory, final DataRow parameterDataRow ) throws ReportDataFactoryException, MessagingException { if ( definition.getRecipientsQuery() != null && dataFactory.isQueryExecutable( definition.getRecipientsQuery(), parameterDataRow ) ) { final TableModel model = wrapWithParameters( dataFactory.queryData( definition.getRecipientsQuery(), parameterDataRow ), parameterDataRow ); for ( int r = 0; r < model.getRowCount(); r++ ) { String address = null; String name = null; String type = "TO"; if ( model.getColumnCount() >= 3 ) { type = (String) model.getValueAt( 0, 2 ); } if ( model.getColumnCount() >= 2 ) { name = (String) model.getValueAt( 0, 1 ); } if ( model.getColumnCount() >= 1 ) { address = (String) model.getValueAt( 0, 0 ); } if ( address == null ) { continue; } if ( name == null ) { message.addRecipient( parseType( type ), new InternetAddress( address, true ) ); } else { try { message.addRecipient( parseType( type ), new InternetAddress( address, name, "UTF-8" ) ); } catch ( UnsupportedEncodingException e ) { // Should not happen - UTF-8 is safe to use throw new MessagingException( "Failed to encode recipient", e ); } } } } }
Example 15
Source File: StringListEditor.java From CppTools with Apache License 2.0 | 5 votes |
public String getText() { final TableModel tableModel = stringListTable.getModel(); final int rowCount = tableModel.getRowCount(); final StringBuilder result = new StringBuilder(rowCount * 50); for (int i = 0; i < rowCount; ++i) { final Object o = getStringAtIndex(tableModel, i); //tableModel.getValueAt(i, 0); if (!(o instanceof String) || ((String)o).length() == 0) continue; if (result.length() > 0) result.append(CppSupportSettings.PATH_SEPARATOR); result.append(o); } return result.toString(); }
Example 16
Source File: JTableOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Searches cell coordinates in the specified rows and columns. * * @param chooser cell verifying object. * @param rows rows to search in * @param columns columns to search in * @param index an ordinal cell index * @return Point indicating coordinates (x - column, y - row) */ public Point findCell(TableCellChooser chooser, int[] rows, int[] columns, int index) { TableModel model = getModel(); int[] realRows; if (rows != null) { realRows = rows; } else { realRows = new int[model.getRowCount()]; for (int i = 0; i < model.getRowCount(); i++) { realRows[i] = i; } } int[] realColumns; if (columns != null) { realColumns = columns; } else { realColumns = new int[model.getColumnCount()]; for (int i = 0; i < model.getColumnCount(); i++) { realColumns[i] = i; } } int count = 0; for (int realRow : realRows) { for (int realColumn : realColumns) { if (chooser.checkCell(this, realRow, realColumn)) { if (count == index) { return new Point(realColumn, realRow); } else { count++; } } } } return new Point(-1, -1); }
Example 17
Source File: VTAddToSessionTest.java From ghidra with Apache License 2.0 | 5 votes |
private int getRowWithFieldValueInColumn(String string, TableModel model, int column) { int rowCount = model.getRowCount(); for (int row = 0; row < rowCount; row++) { if (string.equals(model.getValueAt(row, column))) { return row; } } return -1; }
Example 18
Source File: XMLExporter.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected void writeData(TableModel model, String title, Writer writer, TracerProgressObject progress) throws IOException { int columnsCount = model.getColumnCount(); int rowsCount = model.getRowCount(); writeLine(writer, " <TableData NumRows=\"" + rowsCount + // NOI18N "\" NumColumns=\"" + columnsCount + "\">"); // NOI18N writeLine(writer, " <TableHeader>"); // NOI18N for (int c = 0; c < columnsCount; c++) writeLine(writer, " <TableColumn>" + model.getColumnName(c) + "</TableColumn>"); // NOI18N writeLine(writer, " </TableHeader>"); // NOI18N writeLine(writer, " <TableBody>"); // NOI18N for (int r = 0; r < rowsCount; r++) { writeLine(writer, " <TableRow>"); // NOI18N for (int c = 0; c < columnsCount; c++) writeLine(writer, " <TableColumn>" + model.getValueAt(r, c) + "</TableColumn>"); // NOI18N writeLine(writer, " </TableRow>"); // NOI18N if (progress.isFinished()) break; if (step == 1) { progress.addStep(); } else { int currentStep = (int)(r * step); if (currentStep > lastStep) { progress.addStep(); lastStep = currentStep; } } } writeLine(writer, " </TableBody>"); // NOI18N writeLine(writer, " </TableData>"); // NOI18N }
Example 19
Source File: ShowElementIfDataAvailableExpression.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Computes the visibility state. * * @return true, if there is data available, false otherwise. */ private boolean isDataAvailable() { final ExpressionRuntime runtime = getRuntime(); if ( runtime == null ) { return false; } final TableModel data = runtime.getData(); if ( data == null ) { return false; } if ( data.getRowCount() == 0 ) { return false; } return true; }
Example 20
Source File: MailProcessor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public static void performBursting( final MailDefinition definition, final Session session ) throws MessagingException, ReportProcessingException, ContentIOException { if ( session == null ) { throw new NullPointerException(); } // process parameters - validate! final ReportParameterValues parameterValues = definition.getParameterValues(); final DefaultParameterContext parameterContext = new DefaultParameterContext( definition.getDataFactory(), parameterValues, ClassicEngineBoot.getInstance() .getGlobalConfig(), definition.getResourceBundleFactory(), definition.getResourceManager(), definition .getContextKey(), definition.getReportEnvironment() ); try { final ReportParameterDefinition parameterDefinition = definition.getParameterDefinition(); final ReportParameterValidator reportParameterValidator = parameterDefinition.getValidator(); final ValidationResult validationResult = reportParameterValidator.validate( new ValidationResult(), parameterDefinition, parameterContext ); if ( validationResult.isEmpty() == false ) { throw new ReportParameterValidationException( "The parameters provided for this report are not valid.", validationResult ); } } finally { parameterContext.close(); } // definition: Single mail or multi-mail final TableModel burstingData; final DataFactory dataFactory = definition.getDataFactory(); if ( definition.getBurstQuery() != null && dataFactory.isQueryExecutable( definition.getBurstQuery(), parameterValues ) ) { burstingData = wrapWithParameters( dataFactory.queryData( definition.getBurstQuery(), parameterValues ), parameterValues ); } else { burstingData = wrapWithParameters( new DefaultTableModel( 1, 0 ), parameterValues ); } if ( burstingData.getRowCount() > 0 ) { // final Transport transport = session.getTransport(); // transport.connect(); for ( int i = 0; i < burstingData.getRowCount(); i++ ) { final DataRow parameterDataRow = createReportParameterDataRow( burstingData, i ); final MimeMessage message = createReport( definition, session, parameterDataRow ); parameterContext.setParameterValues( parameterDataRow ); final MailHeader[] headers = definition.getHeaders(); for ( int j = 0; j < headers.length; j++ ) { final MailHeader header = headers[j]; message.addHeader( header.getName(), header.getValue( parameterContext ) ); } processRecipients( definition, message, dataFactory, parameterDataRow ); // transport.sendMessage(message, message.getAllRecipients()); } // transport.close(); } }