如何使Scroll窗格静态? [英] How to make Scroll pane static?

查看:197
本文介绍了如何使Scroll窗格静态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

观察::

每当用户到达表格中的最后一个单元格并按Tab键时,焦点就会转移到第一个单元格,即表格顶部。

Whenever the user reaches the last cell in the table and press Tab key, the focus is shifted to the first cell i.e the top the table.

通过使用函数 table.scrollRectToVisible(rect)将表格视图带回到最后一个单元格,但由于这个原因,看起来表值中有一个错误的变化。

Brought the table view back to the last cell, by using the function table.scrollRectToVisible(rect), but due this there is movement and looks like there is a false change in the table values.

场景::如果我让make Scroll窗格静态在特定位置,这样我就可以控制运动。怎么能让这成为可能..

The Scenario :: If I have make the make Scroll pane Static at particular position, so that I can control the movement. How can make this possible..

提前谢谢你......

Thank You in Advance...

推荐答案

基本方法是将表的默认导航操作包装到自定义Action中,该Action检查当前单元格:如果它是最后一个,则不执行任何操作,否则执行包装操作

The basic approach is to wrap the table's default navigation action into a custom Action which checks for the current cell: if it's the last, do nothing otherwise execute the wrapped action

代码示例:

    Object key = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .get(KeyStroke.getKeyStroke("ENTER"));
    final Action action = table.getActionMap().get(key);
    Action custom = new AbstractAction("wrap") {

        @Override
        public void actionPerformed(ActionEvent e) {
            // implement your prevention logic
            // here: don't perform if the current cell focus is the very cell of the table
            int row = table.getSelectionModel().getLeadSelectionIndex();
            if (row == table.getRowCount() - 1) {
                int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
                if (column == table.getColumnCount() -1) {
                    // if so, do nothing and return
                    return;
                }
            }
            // if not, call the original action
            action.actionPerformed(e);
        }

    };
    table.getActionMap().put(key, custom);

这篇关于如何使Scroll窗格静态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆