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

The following examples show how to use javax.swing.table.TableModel#setValueAt() . 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 vote down vote up
@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 vote down vote up
private void groceriesjTableKeyReleased(java.awt.event.KeyEvent evt) {
	if (evt.getKeyCode() == evt.VK_ENTER) {
		int row = Command.JframeSaoHuo.groceriesjTable.getSelectedRow();
		Lang lang = new Func.Lang();
		SaoHuoFunc saoHuoFunc = new SaoHuoFunc();
		//			
		//			
		TableModel model = (TableModel) Command.JframeSaoHuo.groceriesjTable
				.getModel();
		String now = model.getValueAt(row, 2).toString();
		model.setValueAt(saoHuoFunc.moneyToString(lang.Integer_(now, 2)),
				row, 1);

		saoHuoFunc = null;
		lang = null;
		model = null;
	}

}
 
Example 3
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void petjTableKeyReleased(java.awt.event.KeyEvent evt) {
	if (evt.getKeyCode() == evt.VK_ENTER) {
		int row = Command.JframeSaoHuo.petjTable.getSelectedRow();
		Lang lang = new Func.Lang();
		SaoHuoFunc saoHuoFunc = new SaoHuoFunc();
		//			
		//			
		TableModel model = (TableModel) Command.JframeSaoHuo.petjTable
				.getModel();
		String now = model.getValueAt(row, 2).toString();
		model.setValueAt(saoHuoFunc.moneyToString(lang.Integer_(now, 2)),
				row, 1);

		saoHuoFunc = null;
		lang = null;
		model = null;
	}
}
 
Example 4
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void jButton1ActionPerformed(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.groceriesjTable
				.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: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void fengWuZhijTableKeyReleased(java.awt.event.KeyEvent evt) {
	if (evt.getKeyCode() == evt.VK_ENTER) {
		int row = Command.JframeSaoHuo.fengWuZhijTable.getSelectedRow();
		Lang lang = new Func.Lang();
		SaoHuoFunc saoHuoFunc = new SaoHuoFunc();
		//			
		//			
		TableModel model = (TableModel) Command.JframeSaoHuo.fengWuZhijTable
				.getModel();
		String now = model.getValueAt(row, 2).toString();
		model.setValueAt(saoHuoFunc.moneyToString(lang.Integer_(now, 2)),
				row, 1);

		saoHuoFunc = null;
		lang = null;
		model = null;
	}
}
 
Example 6
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
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 7
Source File: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 6 votes vote down vote up
@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 8
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@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 9
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void jButton8ActionPerformed(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.elseClassjTable
				.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 10
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@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 11
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void jButton2ActionPerformed(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.stonejTable
				.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 12
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void elseClassjTableKeyReleased(java.awt.event.KeyEvent evt) {
	if (evt.getKeyCode() == evt.VK_ENTER) {
		int row = Command.JframeSaoHuo.elseClassjTable.getSelectedRow();
		Lang lang = new Func.Lang();
		SaoHuoFunc saoHuoFunc = new SaoHuoFunc();
		//			
		//			
		TableModel model = (TableModel) Command.JframeSaoHuo.elseClassjTable
				.getModel();
		String now = model.getValueAt(row, 2).toString();
		model.setValueAt(saoHuoFunc.moneyToString(lang.Integer_(now, 2)),
				row, 1);

		saoHuoFunc = null;
		lang = null;
		model = null;
	}
}
 
Example 13
Source File: SaoHuo.java    From xunxian with Apache License 2.0 6 votes vote down vote up
private void stonejTableKeyReleased(java.awt.event.KeyEvent evt) {
	if (evt.getKeyCode() == evt.VK_ENTER) {
		int row = Command.JframeSaoHuo.stonejTable.getSelectedRow();
		Lang lang = new Func.Lang();
		SaoHuoFunc saoHuoFunc = new SaoHuoFunc();
		//			
		//			
		TableModel model = (TableModel) Command.JframeSaoHuo.stonejTable
				.getModel();
		String now = model.getValueAt(row, 2).toString();
		model.setValueAt(saoHuoFunc.moneyToString(lang.Integer_(now, 2)),
				row, 1);

		saoHuoFunc = null;
		lang = null;
		model = null;
	}
}
 
Example 14
Source File: TemplateClientPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({
    "TemplateClientPanelVisual.lbl.select.valid.template=Select valid or non-empty template..."
})
private static TableModel getNoTemplateTableModel() {
    TableModel model = new DefaultTableModel(1, 1);
    model.setValueAt(Bundle.TemplateClientPanelVisual_lbl_select_valid_template(), 0, 0);
    return model;
}
 
Example 15
Source File: PullUpOperator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setValueAt(int y, int x, boolean val){
    JTableOperator table = new JTableOperator(this, 0); 
    JTable t = ((JTable)table.getSource());                
    TableModel model = t.getModel();
    model.setValueAt(val, y, x);
}
 
Example 16
Source File: NameValueCellEditor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void showParamEditor() {

	int currentRow = table.getSelectedRow();
	TableModel model = table.getModel();
	String name =  (String)model.getValueAt(currentRow, 0);
	String value = (String)model.getValueAt(currentRow, 1);

	ParamEditor.Condition condition = ParamEditor.Condition.NONE; 
	ParamEditor.Editable editable = ParamEditor.Editable.BOTH; 
	String title = null; 
	
	if(debug) 
	    System.out.println("type = " + String.valueOf(type)); //NOI18N

	if(type == DisplayTable.UNEDITABLE) {
	    editable = ParamEditor.Editable.NEITHER;
	    title = NbBundle.getMessage(NameValueCellEditor.class, 
					"MON_ParamValue"); 
	}
	else if(type == DisplayTable.HEADERS) {
	    title = NbBundle.getMessage(NameValueCellEditor.class, 
					"MON_Edit_header"); 
	    condition = ParamEditor.Condition.HEADER; 
	}
	else if(type == DisplayTable.PARAMS) 
	    title = NbBundle.getMessage(NameValueCellEditor.class, 
					"MON_Edit_param");  
	else if(type == DisplayTable.REQUEST) {
	    editable = ParamEditor.Editable.VALUE;
	    title = NbBundle.getMessage(NameValueCellEditor.class, 
					"MON_Edit_request"); 
	    condition = ParamEditor.Condition.VALUE;
	}
	else if(type == DisplayTable.COOKIES) {
	    title = NbBundle.getMessage(NameValueCellEditor.class, 
					"MON_Edit_cookie"); 
	    condition = ParamEditor.Condition.COOKIE; 
	}
	else if(type == DisplayTable.SERVER) {
	    title = NbBundle.getMessage(NameValueCellEditor.class, 
					"MON_Edit_server"); 
	    condition = ParamEditor.Condition.VALUE; 
	    editable = ParamEditor.Editable.VALUE;
	}
	// This should not happen
	else 
	    title = NbBundle.getMessage(NameValueCellEditor.class, "MON_Edit_value"); 
	


	ParamEditor pe = new ParamEditor(name, value, editable, condition,
					 title); 

	pe.showDialog(); 

	if(debug) 
	    System.out.println("NameValueCellEditor::has " + //NOI18N
			       pe.getName() + " " + pe.getValue());//NOI18N

	if ((type > DisplayTable.UNEDITABLE) && pe.getDialogOK()) {
	    if(debug) System.out.println("Updating the model");//NOI18N
	    
	    if (nameEditable) {
		model.setValueAt(pe.getName(), currentRow, 0);
		if(debug) System.out.println("Updated the name");//NOI18N
	    }
	    model.setValueAt(pe.getValue(), currentRow, 1);
	    if(debug) System.out.println("Updated the value");//NOI18N
	}
    }
 
Example 17
Source File: ProjectImporterTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected static void selectProjectByIndex(TableModel model, int index) {
    model.setValueAt(true, index, 0);
}
 
Example 18
Source File: EncapsulateFieldOperator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setValueAt(int y, int x, String val){
    JTableOperator table = new JTableOperator(this, 0); 
    JTable t = ((JTable)table.getSource());                
    TableModel model = t.getModel();
    model.setValueAt(val, y, x);
}
 
Example 19
Source File: EncapsulateFieldOperator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setValueAt(int y, int x, boolean val){
    JTableOperator table = new JTableOperator(this, 0); 
    JTable t = ((JTable)table.getSource());                
    TableModel model = t.getModel();
    model.setValueAt(val, y, x);
}
 
Example 20
Source File: PushDownOperator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setValueAt(int y, int x, boolean val){
    JTableOperator table = new JTableOperator(this, 0); 
    JTable t = ((JTable)table.getSource());                
    TableModel model = t.getModel();
    model.setValueAt(val, y, x);
}