Here you can find the source of spaceSelection(final JTable jTable)
Parameter | Description |
---|---|
jTable | The table this method shall be used on |
public static void spaceSelection(final JTable jTable)
//package com.java2s; /* /*ww w.ja v a2 s . c om*/ * Copyright (C) 2014 GG-Net GmbH - Oliver G?nther * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JTable; public class Main { /** * Let a CheckBoxTableModel using JTable select a value by pressing * space on the keyboard. * @param jTable The table this method shall be used on */ public static void spaceSelection(final JTable jTable) { jTable.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent evt) { if (evt.getKeyCode() != KeyEvent.VK_SPACE || jTable.getSelectedRow() == -1) return; if (jTable.getValueAt(jTable.getSelectedRow(), 0) == Boolean.TRUE) { jTable.setValueAt(false, jTable.getSelectedRow(), 0); } else { jTable.setValueAt(true, jTable.getSelectedRow(), 0); } } }); } }