Java Code Examples for javax.swing.event.TableModelEvent

Following code examples demonstrate how to use javax.swing.event.TableModelEventfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use javax.swing.event.TableModelEventand various code implementation of this class.

	public void tableChanged(TableModelEvent e) {
		switch (e.getType()) {
		case TableModelEvent.DELETE:
		case TableModelEvent.UPDATE:
			if (e.getColumn() == TableModelEvent.ALL_COLUMNS)
				;
			else
				;
			break;
		case TableModelEvent.INSERT:
			break;
		default:
		}

	} 


    public void tableChanged(TableModelEvent arg0) {
        PartPropertiesTableModel pptm = (PartPropertiesTableModel) arg0.getSource();
        pptm.fireTableRowsUpdated(arg0.getFirstRow(), arg0.getLastRow());
    } 

	public void tableChanged(TableModelEvent e) {
		switch (e.getType()) {
		case TableModelEvent.DELETE:
		case TableModelEvent.UPDATE:
			if (e.getColumn() == TableModelEvent.ALL_COLUMNS)
				;
			else
				;
			break;
		case TableModelEvent.INSERT:
			break;
		default:
		}

	} 

    protected void updateAdapterFromDelegate(TableModelEvent e) {
        if (e.getType() == UPDATE &&
                !isFirstToLastRow(e))
            return;
        if (getDelegate().isContinousRange())
            return;

        label.setText(Integer.toString(getDelegate().getRowCount()));
    } 

  public void addRow(String cs, String desc) {  
	Criteria parent = window.getSelectedPath();  
	Alternative alt=new Alternative(); 
	alt.setName(cs);
	alt.setComment(desc);
    parent.addAlternative(alt);
    at.tableChanged(new TableModelEvent(this, parent.getNumAlternatives()-1,  parent.getNumAlternatives()-1, javax.swing.event.TableModelEvent.ALL_COLUMNS, javax.swing.event.TableModelEvent.INSERT) );
    fireTableRowsInserted(parent.getNumAlternatives()-1,parent.getNumAlternatives()-1);
    window.updateafteraddALTERNATIVE(alt);

  } 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to TableModelEvent.class!",
                   TableModelEvent.class.isAssignableFrom(sut));
    } 

	public void tableChanged(TableModelEvent event) {
		int column = event.getColumn();
		int row = event.getFirstRow();
		if (!this.variableFrame.functionFrameModel.isCellEditable(row, column)) {
			return;
		}
		EditableVariable label = (EditableVariable) this.variableFrame.functionFrameModel.getOldValue(row, column);
		String newValue = this.variableFrame.functionFrameModel.getNewValue(row, column).toString().trim();
		if (label.area == MemoryArea.LOCAL) {
			Object variable = this.variableFrame.machine.functionStack[label.address];
			try {
				Object updateValue = this.variableFrame.update(variable, newValue);
				this.variableFrame.machine.functionStack[label.address] = updateValue;
				this.variableFrame.functionFrameModel.updateVariable(row, column, updateValue);
			} catch (Exception e) {
				JOptionPane.showMessageDialog(this.variableFrame, "变量类型不对,你输入内容的无法转换为boolean,int或者real");
			}
		} else {
			Object variable = this.variableFrame.machine.staticVariables[label.address];
			try {
				Object updateValue = this.variableFrame.update(variable, newValue);
				this.variableFrame.machine.staticVariables[label.address] = updateValue;
				this.variableFrame.functionFrameModel.updateVariable(row, column, updateValue);
			} catch (Exception e) {
				JOptionPane.showMessageDialog(this.variableFrame, "变量类型不对,你输入内容的无法转换为boolean,int或者real");
			}
		}
	} 

  public void addRow(String name, double rate, double usage) {  
	  CustomerGroup cg = new CustomerGroup(name, rate, usage);
	  s.addCustomerGroup(cg);
      cgt.tableChanged(new TableModelEvent(this, s.getNumCustomerGroups()-1,  s.getNumCustomerGroups()-1, javax.swing.event.TableModelEvent.ALL_COLUMNS, javax.swing.event.TableModelEvent.INSERT) );
      fireTableRowsInserted(s.getNumCustomerGroups()-1,s.getNumCustomerGroups()-1);
  } 

    public void tableChanged(TableModelEvent event) {
        if (event.getType() == UPDATE) {

            boolean setToEnabled = updateModel(event);
            setEnableTheBookContractorButton(setToEnabled);
        }

        if (event.getType() == DELETE) {
            setEnableTheBookContractorButton(FALSE);
        }
    } 

    private boolean updateModel(TableModelEvent event) {
        boolean enableBookContractorButton = FALSE;
        ContractorRow recentUpdatedModel = getMostRecentContractorRowModelUpdated(event);

        for (ContractorRow contractorRow : contractorTable.getAllContractorRowModels()) {

            if (!isSelected(contractorRow)) {
                continue;
            }

            enableBookContractorButton = TRUE;

            if (isSameModel(recentUpdatedModel, contractorRow)) {
                continue;
            }

            if (isSelected(recentUpdatedModel)) {
                unSelectModel(contractorRow);
                break;
            }
        }
        return enableBookContractorButton;
    } 

	public void tableChanged(TableModelEvent e) {
		switch (e.getType()) {
		case TableModelEvent.DELETE:
		case TableModelEvent.UPDATE:
			if (e.getColumn() == TableModelEvent.ALL_COLUMNS)
				;
			else
				;
			break;
		case TableModelEvent.INSERT:
			break;
		default:
		}

	} 

  
  public void fireTableChanged(final TableModelEvent e)
  {
    if (suspendEvents)
    {
      return;
    }
    super.fireTableChanged(e);
  } 

Advertisement
Javadoc
TableModelEvent is used to notify listeners that a table model has changed. The model event describe

s changes to a TableModel and all references to rows and columns are in the co-ordinate system of the model. Depending on the parameters used in the constructors, the TableModelevent can be used to specify the following types of changes: TableModelEvent(source); // The data, ie. all rows changed TableModelEvent(source, HEADER_ROW); // Structure change, reallocate TableColumns TableModelEvent(source, 1); // Row 1 changed TableModelEvent(source, 3, 6); // Rows 3 to 6 inclusive changed TableModelEvent(source, 2, 2, 6); // Cell at (2, 6) changed TableModelEvent(source, 3, 6, ALL_COLUMNS, INSERT); // Rows (3, 6) were inserted TableModelEvent(source, 3, 6, ALL_COLUMNS, DELETE); // Rows (3, 6) were deleted It is possible to use other combinations of the parameters, not all of them are meaningful. By subclassing, you can add other information, for example: whether the event WILL happen or DID happen. This makes the specification of rows in DELETE events more useful but has not been included in the swing package as the JTable only needs post-event notification.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans package. Please see java.beans.XMLEncoder. @author Alan Chung @author Philip Milne @see TableModel

Read More
Advertisement