jtable中根据鼠标滑轮滚动改变单元格(列)里的值

原文转自: jtable中根据鼠标滑轮滚动改变单元格(列)里的值
dataTable.addMouseWheelListener(new MouseWheelListener(){

	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		Object o = e.getSource();
		if(o instanceof JTable){
			JTable t = (JTable) o;
			DefaultTableModel tb = (DefaultTableModel) t.getModel();
			if(tb.isCellEditable(t.getSelectedRow(), t.getSelectedColumn())){
				Object v = tb.getValueAt(t.getSelectedRow(), t.getSelectedColumn());
				if(v!= null && v.toString().matches("\\d+")){
					int v2 = (Integer.parseInt(v.toString())+ e.getWheelRotation());
					v2 = v2>=0?v2:0;
					tb.setValueAt(v2, t.getSelectedRow(), t.getSelectedColumn());
				}
				
			}
		}
	}
			
});

              

你可能感兴趣的:(html)