Java Code Examples for javax.swing.table.TableModel#getValueAt()

The following examples show how to use javax.swing.table.TableModel#getValueAt() . 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: CachingDataFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Prints a table model to standard output.
 *
 * @param mod
 *          the model.
 */
public static void printTableModelContents( final TableModel mod ) {
  if ( mod == null ) {
    throw new NullPointerException();
  }

  logger.debug( "Tablemodel contains " + mod.getRowCount() + " rows." ); //$NON-NLS-1$ //$NON-NLS-2$
  for ( int i = 0; i < mod.getColumnCount(); i++ ) {
    logger.debug( "Column: " + i + " Name = " + mod.getColumnName( i ) + "; DataType = " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        + mod.getColumnClass( i ) );
  }

  logger.debug( "Checking the data inside" ); //$NON-NLS-1$
  for ( int rows = 0; rows < mod.getRowCount(); rows++ ) {
    for ( int i = 0; i < mod.getColumnCount(); i++ ) {
      final Object value = mod.getValueAt( rows, i );
      logger.debug( "ValueAt (" + rows + ", " + i + ") is " + value ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
  }
}
 
Example 2
Source File: MainPage.java    From ShoppingCartinJava with MIT License 6 votes vote down vote up
private void mobileTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mobileTableMouseClicked
    // TODO add your handling code here:
    pi.setVisible(true);
    pi.pack();
    
    int selectedRow = mobileTable.getSelectedRow();
    TableModel tm = mobileTable.getModel();
    
    String brand = tm.getValueAt(selectedRow, 0).toString();
    String model = tm.getValueAt(selectedRow, 1).toString();
    String price = tm.getValueAt(selectedRow, 2).toString();
    String stock = tm.getValueAt(selectedRow, 3).toString();
    String feature = tm.getValueAt(selectedRow, 4).toString();
    ImageIcon img = (ImageIcon) tm.getValueAt(selectedRow, 5);
    
    pi.productInfoBrandName.setText(brand);
    pi.productInfoModel.setText(model);
    pi.productInfoPrice.setText(price);
    pi.productInfoStock.setText(stock);
    pi.productInfoFeature.setText(feature);
    pi.productPhoto.setIcon(img);
}
 
Example 3
Source File: TableUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static int moveSelectedItemsDown(@Nonnull JTable table) {
  if (table.isEditing()){
    table.getCellEditor().stopCellEditing();
  }
  TableModel model = table.getModel();
  ListSelectionModel selectionModel = table.getSelectionModel();
  int counter = 0;
  for(int row = model.getRowCount() - 1; row >= 0 ; 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.getMaxSelectionIndex(), 0, true);
  if (cellRect != null) {
    table.scrollRectToVisible(cellRect);
  }
  table.repaint();
  return counter;
}
 
Example 4
Source File: TableEditorModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void copyInto( final TableModel model ) {
  try {
    setSuspendEvents( true );
    clear();
    if ( model == null ) {
      return;
    }

    final int columnCount = model.getColumnCount();
    for ( int col = 0; col < columnCount; col++ ) {
      addColumn( model.getColumnName( col ), model.getColumnClass( col ) );
    }

    final int rowCount = model.getRowCount();
    for ( int r = 0; r < rowCount; r++ ) {
      addRow();
      for ( int col = 0; col < columnCount; col++ ) {
        final Object originalValue = model.getValueAt( r, col );
        setValueAt( originalValue, r, col + 1 );
      }
    }
  } finally {
    setSuspendEvents( false );
  }
}
 
Example 5
Source File: CategoryPanelStepFilters.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: ProprietiesListener.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    
    if (e.getType() == TableModelEvent.UPDATE) {
        EditAttributeCommand command = CommandProcessor.getInstance().getCommand(EditAttributeCommand.class);
        RemoveAttributeCommand removecommand = CommandProcessor.getInstance().getCommand(RemoveAttributeCommand.class);
        TableModel mod = (TableModel) e.getSource();
        String proName = (String) mod.getValueAt(e.getLastRow(), 0);
        String proVal = (String) mod.getValueAt(e.getLastRow(), 1);
        if (proName != null && !proName.isEmpty()) {
            try{
            if (proVal == null || proVal.isEmpty()) {
                removecommand.setAttributeKey(proName);
                CommandProcessor.getInstance().excuteCommand(removecommand);
            } else {
               command.setAttribute(proName);
               command.setValue(proVal);
               CommandProcessor.getInstance().excuteCommand(command);
            }
            }catch(Exception ex){
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null,"Can't set the attribute. " + ex.getMessage());
            }
        }
    }
}
 
Example 7
Source File: EquatePlugin1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleEquatesSameValue() throws Exception {

	createSameValueDifferentNameEquates();

	putCursorOnOperand(0x010062d6, 1);

	SetEquateDialog d = showSetEquateDialog();

	GhidraTable table = findComponent(d.getComponent(), GhidraTable.class);
	assertNotNull(table);

	TableModel model = table.getModel();
	assertEquals(5, model.getRowCount());
	for (int i = 0; i < 5; i++) {
		String value = (String) model.getValueAt(i, 0);
		assertTrue(value.startsWith("MY_EQUATE_"));
	}

	cancel(d);
}
 
Example 8
Source File: TableUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 9
Source File: RepListColumnSetupDialog.java    From scelight with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent event ) {
 final TableModel model = table.getModel();
 
 for ( final int row : table.getSelectedModelRows() ) {
  @SuppressWarnings( "unchecked" )
  final Class< IColumn< ? > > colClass = (Class< IColumn< ? > >) model.getValueAt( row, 0 );
  // Date column is mandatory, do not hide it!
  if ( !DateColumn.class.equals( colClass ) )
   rlcBean.getColumnClassList().remove( colClass );
 }
 
 rebuildTable();
}
 
Example 10
Source File: OkJsonFastEditor.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
private HashMap<String, Object> getJsonData(TableModel model) {
    HashMap<String, Object> hashMap = new HashMap<>(16);
    for (int i = 0, l = model.getRowCount(); i < l; i++) {
        String key = String.valueOf(model.getValueAt(i, 0));
        Object value = model.getValueAt(i, 1);
        if (value != null && !"".equals(String.valueOf(value))) {
            hashMap.put(key, value);
        }
    }
    return hashMap;
}
 
Example 11
Source File: ProjectImporterTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static int getIndexByName(TableModel model, String projectName) {
    int length = model.getRowCount();
    String name;
    for(int i =0; i< length; i++) {
        name = (String)model.getValueAt(i, 1);
        if(name.startsWith(projectName)) return i;
    }
    return 0;
}
 
Example 12
Source File: TableSorter.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static int compareNumbers(TableModel data, int row1, int column, int row2) {
    Number n1 = (Number) data.getValueAt(row1, column);
    double d1 = n1.doubleValue();
    Number n2 = (Number) data.getValueAt(row2, column);
    double d2 = n2.doubleValue();

    if (d1 < d2)
        return -1;
    if (d1 > d2)
        return 1;
    return 0;
}
 
Example 13
Source File: DataManager.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
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 14
Source File: SpringXMLConfigNamespacesVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public String[] getIncludedNamespaces() {
    List<String> incs = new ArrayList<String>();
    TableModel model = includesTable.getModel();

    for(int i = 0; i < model.getRowCount(); i++) {
        Boolean selected = (Boolean) model.getValueAt(i, 0);
        if(selected != null && selected == Boolean.TRUE) {
            String namespace = (String) model.getValueAt(i, 1);
            incs.add(namespace);
        }
    }
    return incs.toArray(new String[0]);
}
 
Example 15
Source File: CertificatesManagerSettingsPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
	int row = e.getFirstRow();
    int column = e.getColumn();
    if (column == 2) {
        TableModel model = (TableModel) e.getSource();
        Boolean checked = (Boolean) model.getValueAt(row, column);
		certControll.addOrRemoveFromExceptionList(checked);
	}
}
 
Example 16
Source File: VariablesTableAdapter.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    final TableModel tableModel = (TableModel) e.getSource();
    final MosaicOp.Variable[] variables = new MosaicOp.Variable[tableModel.getRowCount()];
    for (int i = 0; i < variables.length; i++) {
        variables[i] = new MosaicOp.Variable((String) tableModel.getValueAt(i, 0),
                                             (String) tableModel.getValueAt(i, 1));
    }
    getBinding().setPropertyValue(variables);
}
 
Example 17
Source File: OrdersTable.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
  TableModel tableModel = getModel();
  Object value = tableModel.getValueAt(row, column);
  TableCellRenderer renderer = getDefaultRenderer(value.getClass());

  return renderer;
}
 
Example 18
Source File: OrdersTable.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
  TableModel tableModel = getModel();
  Object value = tableModel.getValueAt(row, column);
  TableCellEditor editor = getDefaultEditor(value.getClass());

  return editor;
}
 
Example 19
Source File: AbstractFileListEditor.java    From CppTools with Apache License 2.0 4 votes vote down vote up
protected Object getStringAtIndex(TableModel tableModel, int i) {
  return tableModel.getValueAt(i, 0);
}
 
Example 20
Source File: TableSorter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader h = (JTableHeader) e.getSource();
    JTable table = h.getTable();
    int selectedRow = table.getSelectedRow();
    TableModel model = table.getModel();
    //remember selection to keep after sorting
    Object selectedAction=null;
    int objectColumn=-1;
    if(selectedRow>-1) {
        for(int i=0; i<table.getColumnCount(); i++) {
            //first find colum with appropriate object
            if(model.getValueAt(selectedRow, i) instanceof ActionHolder) {
                //remember this object
                selectedAction=model.getValueAt(selectedRow, i);
                objectColumn=i;
                //stop edition as we click somewhere ouside of editor
                TableCellEditor editor=table.getCellEditor();
                if(editor!=null) {
                    editor.stopCellEditing();
                }
                break;
            }
        }
    }
    TableColumnModel columnModel = h.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = columnModel.getColumn(viewColumn).getModelIndex();
    if (column != -1) {
        int status = getSortingStatus(column);
        if (!e.isControlDown()) {
            cancelSorting();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or 
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. 
        status = status + (e.isShiftDown() ? -1 : 1);
        status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setSortingStatus(column, status);
        //reselect the same object
        if(selectedAction!=null)setSelectedRow(table, selectedAction, objectColumn);
    }
}