Java Code Examples for javax.swing.JTable#getValueAt()

The following examples show how to use javax.swing.JTable#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: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private MouseListener createExpressionEditorMouseListener(final JTable table, final boolean booleanExpected) {
    final MouseAdapter mouseListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                final int column = table.getSelectedColumn();
                if (column == 1) {
                    table.removeEditor();
                    final int row = table.getSelectedRow();
                    final String[] value = new String[]{(String) table.getValueAt(row, column)};
                    final int i = editExpression(value, booleanExpected);
                    if (ModalDialog.ID_OK == i) {
                        table.setValueAt(value[0], row, column);
                    }
                }
            }
        }
    };
    return MouseEventFilterFactory.createFilter(mouseListener);
}
 
Example 2
Source File: CompanionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
	int row, int column)
{
	background.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
	setBackground(background.getBackground());
	value = table.getValueAt(row, 0);
	if (value instanceof CompanionFacade)
	{
		button.setText(LanguageBundle.getString("in_companionRemove")); //$NON-NLS-1$
	}
	else
	{
		button.setText(LanguageBundle.getString("in_companionCreateNew")); //$NON-NLS-1$
	}
	value = table.getValueAt(row, 1);
	if (value instanceof Boolean)
	{
		button.setEnabled((Boolean) value);
	}
	else
	{
		button.setEnabled(true);
	}
	return this;
}
 
Example 3
Source File: CompanionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
	int column)
{
	background.getTableCellRendererComponent(table, null, true, false, row, column);
	container.setBackground(background.getBackground());
	selectedElement = table.getValueAt(row, 0);
	if (selectedElement instanceof CompanionFacade)
	{
		button.setText(LanguageBundle.getString("in_companionRemove")); //$NON-NLS-1$
		button.setActionCommand(REMOVE_COMMAND);
	}
	else
	{
		button.setText(LanguageBundle.getString("in_companionCreateNew")); //$NON-NLS-1$
		button.setActionCommand(CREATE_COMMAND);
	}
	return container;
}
 
Example 4
Source File: HealthTabRt.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void displayRow(JTable rtTable, int fromRow, int row) {
	long reset_l = (long) rtTable.getValueAt(row, HealthTableModel.RESET_COL);
   	long uptime = (long)rtTable.getValueAt(row, HealthTableModel.UPTIME_COL);
   	//Log.println("RESET: " + reset);
   	//Log.println("UPTIME: " + uptime);
   	int reset = (int)reset_l;
   	maxPayload = Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.MAX_LAYOUT, true);
   	if (maxPayload != null)
   		updateTabMax(maxPayload);
   	minPayload = Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.MIN_LAYOUT, true);
   	if (minPayload != null)
   		updateTabMin(minPayload);
   	realTime = Config.payloadStore.getFramePart(foxId, reset, uptime, Spacecraft.REAL_TIME_LAYOUT, false);
   	if (realTime != null)
   		updateTabRT(realTime, false);
   	if (fromRow == NO_ROW_SELECTED)
   		fromRow = row;
   	if (fromRow <= row)
   		rtTable.setRowSelectionInterval(fromRow, row);
   	else
   		rtTable.setRowSelectionInterval(row, fromRow);
}
 
Example 5
Source File: PlayersTable.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
    Player player = (Player)value;
    if (player == null) {
        NationType nationType
            = (NationType)table.getValueAt(row, ADVANTAGE_COLUMN);
        if (nationType instanceof EuropeanNationType) {
            NationState nationState = (NationState)table
                .getValueAt(row, AVAILABILITY_COLUMN);
            if (nationState == NationState.AVAILABLE) {
                return button;
            }
        }
        Nation nation = (Nation) table.getValueAt(row, NATION_COLUMN);
        label.setText(nation.getRulerName());
    } else {
        label.setText(player.getName());
    }
    return label;
}
 
Example 6
Source File: CompanionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
	int row, int column)
{
	background.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
	setBackground(background.getBackground());
	value = table.getValueAt(row, 0);
	if (value instanceof CompanionFacade)
	{
		button.setText(LanguageBundle.getString("in_companionRemove")); //$NON-NLS-1$
	}
	else
	{
		button.setText(LanguageBundle.getString("in_companionCreateNew")); //$NON-NLS-1$
	}
	value = table.getValueAt(row, 1);
	if (value instanceof Boolean)
	{
		button.setEnabled((Boolean) value);
	}
	else
	{
		button.setEnabled(true);
	}
	return this;
}
 
Example 7
Source File: EquipmentModels.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
	int column)
{
	EquipmentFacade equipment = (EquipmentFacade) table.getValueAt(row, 0);
	int maxQuantity = equipmentList.getQuantity(equipment);
	int minQuantity = 1;
	if (maxQuantity <= 0)
	{
		minQuantity = maxQuantity = 0;
	}
	SpinnerNumberModel model =
			new SpinnerNumberModel(((Integer) value).intValue(), minQuantity, maxQuantity, 1);
	spinner.setModel(model);
	return spinner;
}
 
Example 8
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  JComboBox<Version> combo = (JComboBox<Version>)super.getTableCellEditorComponent(table, value, isSelected, row, column);
  DefaultComboBoxModel<Version> model = (DefaultComboBoxModel<Version>)combo.getModel();
  model.removeAllElements();
  UpgradeXGAPP.UpgradePath path = (UpgradeXGAPP.UpgradePath)table.getValueAt(row, -1);
  for(Version v : path.getVersions()) {
    model.addElement(v);
  }
  combo.setSelectedItem(value); // which must be one of the available ones
  return combo;
}
 
Example 9
Source File: MyTablePanel.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column,
		String columnName, TableModel tableModel, JTable table) {
	Object value = table.getValueAt(row, column);
	if ( value instanceof BasicDBObject ) {
		MongoDBObjectEditor editor = new MongoDBObjectEditor();
		return editor;
	}
	return null;
}
 
Example 10
Source File: ResupplyMissionEditingPanel.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
		int column) {

	// Get type combo box based on first column category value.
	String category = (String) table.getValueAt(row, 0);
	currentCB = typeCBMap.get(category);
	currentCB.setSelectedItem(table.getValueAt(row, column));
	return currentCB;
}
 
Example 11
Source File: IOSpy.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static void setSettings(String appurl, JTable table) {
    url = appurl;
    caps.clear();
    for (int i = 0; i < table.getRowCount(); i++) {
        String key = table.getValueAt(i, 0).toString();
        Object val = table.getValueAt(i, 1);
        if (val == null || val.toString().isEmpty()) {
            continue;
        }
        caps.put(key, val.toString());
    }
}
 
Example 12
Source File: DropboxRevisionsTopComponent.java    From Open-LaTeX-Studio with MIT License 5 votes vote down vote up
private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed
    if (evt.getClickCount() == 2) {
        // Resolving which row has been double-clicked
        Point point = evt.getPoint();
        JTable table = (JTable) evt.getSource();
        int row = table.rowAtPoint(point);
        // Finding revision using information from the clicked row
        Object revisionNumber = table.getValueAt(row, REVISION_COLUMN);
        if (revisionNumber != null) {
            loadRevision(revisionNumber.toString());
        }
    }
}
 
Example 13
Source File: EquipmentModels.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
	int column)
{
	EquipmentFacade equipment = (EquipmentFacade) table.getValueAt(row, 0);
	if (comboBox != null)
	{
		comboBox.removeActionListener(this);
	}
	comboBox = new JComboBox<>(equipMap.getListFor(equipment).toArray());
	comboBox.setSelectedItem(value);
	comboBox.addActionListener(this);
	return comboBox;
}
 
Example 14
Source File: ColumnResizer.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void adjustColumnPreferredWidths(JTable table) {

		TableColumnModel columnModel = table.getColumnModel();

		for (int col = 0; col < table.getColumnCount(); col++) {

			int maxwidth = 0;
			for (int row = 0; row < table.getRowCount(); row++) {

				TableCellRenderer rend = table.getCellRenderer(row, col);
				Object value = table.getValueAt(row, col);
				Component comp = rend.getTableCellRendererComponent(table,
						value, false, false, row, col);
				maxwidth = Math.max(comp.getPreferredSize().width, maxwidth);

			}// END: row loop

			TableColumn column = columnModel.getColumn(col);
			TableCellRenderer headerRenderer = column.getHeaderRenderer();
			if (headerRenderer == null) {
				headerRenderer = table.getTableHeader().getDefaultRenderer();
			}

			Object headerValue = column.getHeaderValue();
			Component headerComp = headerRenderer
					.getTableCellRendererComponent(table, headerValue, false,
							false, 0, col);
			maxwidth = Math.max(maxwidth, headerComp.getPreferredSize().width);
			column.setPreferredWidth(maxwidth);
		}// END: col loop
	}
 
Example 15
Source File: CoverageReportTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    if (value == null) {
        return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
    }

    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {
        super.setForeground(table.getForeground());
        super.setBackground(table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); // NOI18N
        }
        if (border == null) {
            border = UIManager.getBorder("Table.focusCellHighlightBorder"); // NOI18N
        }
        setBorder(border);
    } else {
        setBorder(new EmptyBorder(1, 1, 1, 1));
    }


    FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
    FileObject file = summary.getFile();

    setText(summary.getDisplayName());
    if (file != null && file.isValid()) {
        try {
            DataObject dobj = DataObject.find(file);
            Node node = dobj.getNodeDelegate();
            Image icon = node.getIcon(BeanInfo.ICON_COLOR_32x32);
            setIcon(new ImageIcon(icon));
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
    } else {
        setIcon(null);
    }


    return this;
}
 
Example 16
Source File: CSV.java    From cropplanning with GNU General Public License v3.0 4 votes vote down vote up
public void exportJTable( String filename, String title, JTable jtable) {

    CsvWriter csvOut = new CsvWriter( filename );
    // mark text with double quotes
    csvOut.setTextQualifier('"');
    // set default comment character to hash
    csvOut.setComment('#');

    int columnCount = jtable.getColumnCount();

    try {
      // write comment about date, time, etc
      csvOut.writeComment( " Created by CropPlanning Software" );
      csvOut.writeComment( " Available at https://github.com/claytonrcarter/cropplanning" );
      csvOut.writeComment( " Records exported: " + title );
      csvOut.writeComment( " Exported: " + new Date().toString() );


      String[] buffer = new String[columnCount];


      // create header row
      for ( int col = 0; col < jtable.getColumnCount(); col++ ) {
          String headName;
          if ( jtable instanceof CPSTable )
              headName = jtable.getColumnModel().getColumn(col).getHeaderValue().toString();
          else
              headName = jtable.getColumnName( col );
          buffer[col] = headName;
      }
      csvOut.writeRecord( buffer );

      // now do the rest of the data
      int row;
      for ( row = 0; row < jtable.getRowCount(); row++ ) {
        buffer = new String[columnCount];

         for ( int col = 0; col < jtable.getColumnCount(); col++ ) {
            Object o = jtable.getValueAt( row, col );
//               TODOLists.debug( "PDFExporter", "Row " + row + " column " + col );
//               TODOLists.debug( "PDFExporter", "Value is " + (( o==null) ? "NULL" : o.toString()) );
            if ( o == null ) {
              buffer[col] = "";
            }
            else if ( o instanceof Date )
              buffer[col] = CPSDateValidator.format( (Date) o );
            else if ( o instanceof Float )
              buffer[col] = CPSRecord.formatFloat( ((Float) o).floatValue(), 3);
            else if ( o instanceof Double )
              buffer[col] = CPSRecord.formatFloat( ((Double) o).floatValue(), 3);
            else
              buffer[col] = o.toString();

         }
         csvOut.writeRecord( buffer );
      }

      // write comment "EOF"
      csvOut.writeComment( " End of file" );

      // close
      csvOut.close();

      debug( "exported " + row + " records" );
    }
    catch ( Exception ignore ) { ignore.printStackTrace(); }


  }
 
Example 17
Source File: OrderEntryRenderer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row, int column) {
	
	OrderEntry o = (OrderEntry)table.getValueAt(row, 0);
	
	JLabel comp = new JLabel(String.valueOf(value));
	comp.setFont(MTGControler.getInstance().getFont().deriveFont(Font.PLAIN));
	comp.setHorizontalAlignment(SwingConstants.CENTER);
	comp.setOpaque(true);
	
	if (((OrderEntry) table.getValueAt(row, 0)).isUpdated()) {
		comp.setBackground(Color.GREEN);
		comp.setForeground(table.getForeground());
	}
	else if (isSelected) {
		comp.setBackground(table.getSelectionBackground());
		comp.setForeground(table.getSelectionForeground());
	} else {
		comp.setBackground(table.getBackground());
		comp.setForeground(table.getForeground());
	}
	
	
	try {
		if(value instanceof Double)
		{	
			if (o.getTypeTransaction()==TYPE_TRANSACTION.BUY)
			{
				comp.setIcon(MTGConstants.ICON_OUT);
			}
			else
			{
				comp.setIcon(MTGConstants.ICON_IN);
			}
		}	
		return comp;
	} catch (Exception e) {
		comp.setText(e.getMessage());
		return comp;
	}

}
 
Example 18
Source File: KseFrame.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
public String getNextEntrysAlias() {
	JTable jtKeyStore = getActiveKeyStoreTable();
	int[] rows = jtKeyStore.getSelectedRows();

	// no row selected
	if (rows.length == 0) {
		return null;
	}

	int rowCount = jtKeyStore.getModel().getRowCount();
	if ( rows.length == rowCount) {
		// all rows are selected
		return null;
	} else {
		int idx;
		int max = Arrays.stream(rows).max().getAsInt();
		if (max < (rowCount - 1)) {
			// last selected row is not the last one, return alias of next row
			idx = max + 1;
		} else {
			// last selected row is the last one, return alias of previous row
			int min = Arrays.stream(rows).min().getAsInt();
			if (min >= 1) {
				idx = min - 1;
			} else {
				idx = -1;
				Arrays.sort(rows);
				for (int i = rows.length - 1; i >= 1; i--) {
					if (rows[i] - rows[i - 1] > 1) { // found a gap
						idx = rows[i] - 1;
						break;
					}
				}
			}
		}
		if (idx >= 0) {
			return (String) jtKeyStore.getValueAt(idx, 3);
		} else {
			return null;
		}
	}
}
 
Example 19
Source File: CopyHandler.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
private static void copy(JTable jTable) {
	//Rows
	int[] rows;
	if (jTable.getRowSelectionAllowed()) { //Selected rows
		rows = jTable.getSelectedRows();
	} else { //All rows (if row selection is not allowed)
		rows = new int[jTable.getRowCount()];
		for (int i = 0; i < jTable.getRowCount(); i++) {
			rows[i] = i;
		}
	}

	//Columns
	int[] columns;
	if (jTable.getColumnSelectionAllowed()) { //Selected columns
		columns = jTable.getSelectedColumns();
	} else { //All columns (if column selection is not allowed)
		columns = new int[jTable.getColumnCount()];
		for (int i = 0; i < jTable.getColumnCount(); i++) {
			columns[i] = i;
		}
	}
	StringBuilder tableText = new StringBuilder(); //Table text buffer
	String separatorText = ""; //Separator text buffer (is never added to, only set for each separator)
	int rowCount = 0; //used to find last row

	for (int row : rows) {
		rowCount++; //count rows
		StringBuilder rowText = new StringBuilder(); //Row text buffer
		boolean firstColumn = true; //used to find first column
		for (int column : columns) {
			//Get value
			Object value = jTable.getValueAt(row, column);

			//Handle Separator
			if (value instanceof SeparatorList.Separator) {
				SeparatorList.Separator<?> separator = (SeparatorList.Separator) value;
				Object object = separator.first();
				if (object instanceof CopySeparator) {
					CopySeparator copySeparator = (CopySeparator) object;
					separatorText = copySeparator.getCopyString();
				}
				break;
			}

			//Add tab separator (except for first column)
			if (firstColumn) {
				firstColumn = false;
			} else {
				rowText.append("\t");
			}

			//Add value
			if (value != null) { //Ignore null
				//Format value to displayed value
				if (value instanceof Float) {
					rowText.append(Formater.floatFormat(value));
				} else if (value instanceof Double) {
					rowText.append(Formater.doubleFormat(value));
				} else if (value instanceof Integer) {
					rowText.append(Formater.integerFormat(value));
				} else if (value instanceof Long) {
					rowText.append(Formater.longFormat(value));
				} else if (value instanceof Date) {
					rowText.append(Formater.columnDate(value));
				} else if (value instanceof HierarchyColumn) {
					HierarchyColumn hierarchyColumn = (HierarchyColumn) value;
					rowText.append(hierarchyColumn.getExport());
				} else {
					rowText.append(value.toString()); //Default
				}
			}
		}

		//Add
		if (rowText.length() > 0 || (!separatorText.isEmpty() && rowCount == rows.length)) {
			tableText.append(separatorText); //Add separator text (will be empty for normal tables)
			if (rowText.length() > 0 && !separatorText.isEmpty()) { //Add tab separator (if needed)
				tableText.append("\t");
			}
			tableText.append(rowText.toString()); //Add row text (will be empty if only copying sinlge separator)
			if (rowCount != rows.length) {
				tableText.append("\r\n");
			} //Add end line
		}
	}
	toClipboard(tableText.toString()); //Send it all to the clipboard
}
 
Example 20
Source File: PayPostTableCellRenderer.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 3 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
		int row, int column) {
	
	final Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	
	String rowVal = (String) table.getValueAt(row, 1);
	
	if(isSelected || hasFocus) {
		
		cellComponent.setBackground(table.getSelectionBackground());
	}
	
	else {
	
		if(rowVal.equals("CASH PAYMENT")) {
				
			cellComponent.setBackground(Color.decode("#75dbcf"));
				
		}
		else if(rowVal.equals("SYSTEM")) {
			
			cellComponent.setBackground(Color.decode("#d66c7f"));
		}
		else {
			
			cellComponent.setBackground(table.getBackground());
		}
	}
	return cellComponent;
}