2013-01-04 42 views
2

我在用戶雙擊該行時使用JTable,然後鼠標應該位於下一行。 - >確定 當時滾動條如何在同一poistionSwing:在Jtable中,當光標向下移動時,JScroll欄也應該向下移動?

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(); 
} 




       } 
      } 
     } 

回答

2
+0

當我們雙擊選定的行鼠標應該集中於未來,但選擇應該只選擇行。但是,當滾動窗格出現時,Jscrollpane&鼠標無法移動時就會出現問題。 –

+0

任何建議如何同時移動鼠標和滾動條? –

+0

那裏沒有用JScrollBar與JTable不斷地移動,一切都在你的代碼的其餘部分,東西塊built_in可滾動:-) – mKorbel