从撤消重做操作中忽略文本模式-JAVA

时间:2018-12-14 21:49:14

标签: java swing jtextfield undo-redo

我有一个文本字段,用于表格的过滤器行。

当失去字段焦点时,在文本字段中显示按....项过滤
当获得焦点时,隐藏此字符串

我如何忽略撤消和重做中的按...项过滤

private static final UndoManager MANAGER = new UndoManager();

private boolean isLabel() {
        return filterField.getText().startsWith("Search by") && filterField.getText().endsWith("items");

    }


public void actionPerformed(ActionEvent event) {

if (event.getSource().equals(undoField)) {

            try {

                MANAGER.undo();

                if (isLabel()) {
                    throw new CannotUndoException();

                }

            } catch (CannotUndoException e) {
                System.out.println("cannot undo");

            }

        }

        else if (event.getSource().equals(redoField)) {

            try {

                MANAGER.redo();

                if (isLabel())
                    throw new CannotRedoException();

            } catch (CannotRedoException e) {
                System.out.println("cannot redo");

            }

}

this UI of my program

0 个答案:

没有答案