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

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




                }
            }
        }

最佳答案

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

相关文章:

java - 读取和写入 JSON 文件 Java

java - 添加一个将 JLabel 扩展到带有 gridlayout 的面板中的类

java - JTable 选择其他行并在单击某个单元格时获取其数据

java - 使用 MouseListener 事件在 JTable 中出现 NullPointerException

java - 如何按难度级别显示所有问题

java - 当 SelectionKey 在 java nio 中变为可写时

java - 如何知道 JScrollBar 是否已经到达 JScrollPane 的底部?

java - 尽管我使用了 Swing Timer,但在 JPanel 上从动画绘制 Wave 时 GUI 卡住

java - 如何将 IntBinaryOperator 与 Java Swing 的 Switch Case 语句一起使用? (简单计算器)

java - 如何从 spring boot thymeleaf 获取输入值到java类?