如何选择单击鼠标并在JQGrid中移位类似于(JTable)?

时间:2012-06-11 20:19:10

标签: java jtable listener keylistener listselectionlistener

我有ListSelectionListener告诉我何时用鼠标选择了单元格。

JGrid grid = new JGrid();
grid.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
grid.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

   @Override
   public void valueChanged(final ListSelectionEvent e) {
       e.getFirstIndex();
       e.getLastIndex()
   }
}

我想只在按住班次时才选择卖出。我该怎么做?

我需要它进行多项选择。当用户按住shift并点击单元格时,它会为我提供getFirstIndex()getLastIndex()

1 个答案:

答案 0 :(得分:0)

将类似于此的KeyListener添加到JGrid,假设JGrids采用keyListeners

boolean shiftIsDown = false;

yourJGrid.addKeyListener(new KeyListener()
        {
            public void keyPressed(KeyEvent e)
            {
                if (e.getKeyCode == e.VK_SHIFT) shiftIsDown = true; 
            }

            public void keyReleased(KeyEvent e)
            {
                 if (e.getKeyCode == e.VK_SHIFT && 
                     shiftIsDown == true) shiftIsDown = false;
            }

            public void keyTyped(KeyEvent e)
            {
                // nothing
            }

        });

现在当你得到一个valueChanged()事件时,只需检查你的布尔“shiftIsDown”值是否为真,如果是,你就可以做出选择。