gpt4 book ai didi

java - Swing:在Jtable中,当光标向下移动时,JScroll条也应该向下移动吗?

转载 作者:行者123 更新时间:2023-11-30 09:28:13 26 4
gpt4 key购买 nike

当用户双击该行时,我正在使用 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();
}




}
}
}

最佳答案

关于java - Swing:在Jtable中,当光标向下移动时,JScroll条也应该向下移动吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14157305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com