Swing:在Jtable中,当光标向下移动时,JScroll栏也应向下移动?

时间:2013-01-04 12:33:38

标签: java swing jtable mouselistener awtrobot

当用户双击该行时,我使用JTable,然后鼠标应该在下一行填充。 - >好 当时滚动条如何移动Jscrollbar&小鼠同样的痛苦

public void TableMouseListener implements MouseListener {


public void mouseClicked(MouseEvent e) {

            //if the double click is performed or left button
  if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) {

    Robot r;
    Point p = e.getPoint();
    JTable table = (JTable) e.getSource();
    int rowNumber = table.rowAtPoint(p);
    PointerInfo a1 = MouseInfo.getPointerInfo();
    Point b1 = a1.getLocation();
    int x1 = (int) b1.getX();
    int y1 = (int) b1.getY();
    System.out.println(x1+" :X :  "+x1);
    System.out.println(y1+" : Y : "+y1);

    //Mouse move to next record based row height                
    r = new Robot();
    r.mouseMove(x1, y1 +table.getRowHeight());

    //Can any one suggest move the scrollbar based on the cursor move
    //Rectangle rect = viewport.getViewRect();
    //rect.y = rect.y + table.getRowHeight();
    //viewport.scrollRectToVisible(rect); -> IF scrollbar is used to move but not in next poistion
    } catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}




                }
            }
        }

1 个答案:

答案 0 :(得分:2)