Java Code Examples for java.awt.event.KeyAdapter

The following examples show how to use java.awt.event.KeyAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Explvs-AIO   Source File: DoubleField.java    License: MIT License 6 votes vote down vote up
public DoubleField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new DoubleDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 2
Source Project: Explvs-AIO   Source File: IntegerField.java    License: MIT License 6 votes vote down vote up
public IntegerField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new IntegerDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 3
Source Project: Explvs-AIO   Source File: ItemField.java    License: MIT License 6 votes vote down vote up
public ItemField() {
    setColumns(20);
    addPosibilities(ItemGuide.getAllGEItems().keySet());
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateItemNameField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateItemNameField();
        }
    });
}
 
Example 4
Source Project: Explvs-AIO   Source File: RSUnitField.java    License: MIT License 6 votes vote down vote up
public RSUnitField() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });

    setPlaceholder("100 / 1.2k / etc.");
}
 
Example 5
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 6
@SuppressWarnings({"OverridableMethodCallInConstructor"})
public NativeW() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            //    TextFieldEventPropagate.consumeKeyEvent(pwidget.get(), widget.getCaretPosition(), e.getKeyChar(), true);    // Always click event
        }
    });
    addPropertyChangeListener("page", (PropertyChangeEvent evt) -> {
        isLoading = false;
        // Take care of event that the page  has loaded
        UIWebView wv = getIOSWidget();
        if (wv == null)
            return;
        Native.graphics().refreshDisplay();

        UIWebViewDelegate del = wv.delegate();
        if (del != null)
            del.didFinishLoad(wv);
    });
    setEditable(false);
    addHyperlinkListener(SwingWebWrapper.this);
}
 
Example 7
Source Project: ghidra   Source File: HexOrDecimalInput.java    License: Apache License 2.0 6 votes vote down vote up
public HexOrDecimalInput(Long initialValue) {
	super();
	currentValue = initialValue;
	setDocument(new MyDocument());
	updateText();
	setToolTipText("Press 'M' to toggle Hex or Decimal Mode");
	addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_M) {
				toggleMode();
				repaint();
			}
		}

	});
}
 
Example 8
Source Project: arcusplatform   Source File: Oculus.java    License: Apache License 2.0 6 votes vote down vote up
public static void invokeOnEnter(Component c, Runnable action) {
   if (c instanceof JTextField) {
      ((JTextField)c).addActionListener((evt) -> action.run());
   } else if (c instanceof AbstractButton) {
      ((AbstractButton)c).addActionListener((evt) -> action.run());
   } else {
      c.addKeyListener(new KeyAdapter() {
         @Override
         public void keyPressed(KeyEvent e) {
            if(e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_ENTER) {
               action.run();
            }
         }
      });
   }
}
 
Example 9
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 10
Source Project: jdk8u60   Source File: DisplayChangeVITest.java    License: GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 11
Source Project: Explvs-AIO   Source File: DoubleField.java    License: MIT License 6 votes vote down vote up
public DoubleField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new DoubleDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 12
Source Project: Explvs-AIO   Source File: IntegerField.java    License: MIT License 6 votes vote down vote up
public IntegerField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new IntegerDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 13
Source Project: Explvs-AIO   Source File: ItemField.java    License: MIT License 6 votes vote down vote up
public ItemField() {
    setColumns(20);
    addPosibilities(ItemGuide.getAllGEItems().keySet());
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateItemNameField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateItemNameField();
        }
    });
}
 
Example 14
Source Project: Explvs-AIO   Source File: RSUnitField.java    License: MIT License 6 votes vote down vote up
public RSUnitField() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });

    setPlaceholder("100 / 1.2k / etc.");
}
 
Example 15
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 16
Source Project: netbeans   Source File: OQLControllerUI.java    License: Apache License 2.0 6 votes vote down vote up
public Presenter(final QueryUI queryUI) {
    super();
    setText(Bundle.OQLControllerUI_ControllerName());
    setToolTipText(Bundle.OQLControllerUI_ControllerDescr());
    setIcon(OQL_ICON);

    addKeyListener(new KeyAdapter() {
        public void keyTyped(final KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    queryUI.requestFocus();
                    queryUI.addToQuery(e.getKeyChar());
                }
            });
        }
    });
}
 
Example 17
private KeyListener listenToKeysListener() {
    final KeyAdapter adapter = new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            String word = nameField.getText();
            if (word.length() < 18) {
                hotelNameTitle.setText(word);
                hotelNameTitle.repaint();
            } else {
                JOptionPane.showMessageDialog(modalFrame, "Hotel name maximum 18 charachter allowed!",
                        JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
            }
            super.keyTyped(e);
        }
    };
    return adapter;
}
 
Example 18
private KeyListener validatorListener() {
	final KeyAdapter adapter = new KeyAdapter() {
		@Override
		public void keyTyped(KeyEvent e) {
			final EmailValidator validator = new EmailValidator();
			if(validator.validate(emailField.getText())) {
				markerLbl.setVisible(false);
				infoLabel.setText("");
				isValid = true;
			}
			else {
				markerLbl.setVisible(true);
				infoLabel.setText("Invalid email format!");
			}
		}
	};
	return adapter;
}
 
Example 19
protected void initListeners() {
  // textView.addComponentListener(new ComponentAdapter(){
  // public void componentResized(ComponentEvent e){
  // try{
  // scroller.getViewport().setViewPosition(
  // textView.modelToView(0).getLocation());
  // scroller.paintImmediately(textView.getBounds());
  // }catch(BadLocationException ble){
  // //ignore
  // }
  // }
  // });

  // stop control+H from deleting text and transfers the key to the
  // parent
  textView.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_H && e.isControlDown()) {
        getGUI().dispatchEvent(e);
        e.consume();
      }
    }
  });
}
 
Example 20
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 21
Source Project: ramus   Source File: IconPreviewPanel.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    JScrollPane pane = new JScrollPane();
    list = new JList(dataModel);
    list.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F5) {
                try {
                    data = null;
                    loadImages();
                } catch (IOException e1) {
                    e1.printStackTrace();
                    JOptionPane.showMessageDialog(null, e1
                            .getLocalizedMessage());
                }
                list.setModel(dataModel);
                list.updateUI();
            }
        }
    });
    list.setCellRenderer(new IconRenderer());
    pane.setViewportView(list);
    for (int i = 0; i < data.size(); i++) {
    }
    this.add(pane, BorderLayout.CENTER);
}
 
Example 22
Source Project: openjdk-jdk9   Source File: bug6578666.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void createGui() {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tree = new JTree();
    frame.add(tree);

    tree.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            tree.updateUI();
        }
    });

    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 23
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 24
Source Project: hottub   Source File: DisplayChangeVITest.java    License: GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example 25
Source Project: Explvs-AIO   Source File: DateField.java    License: MIT License 5 votes vote down vote up
public DateField() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example 26
Source Project: blog-codes   Source File: mxGraphComponent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Handles escape keystrokes.
 */
protected void installKeyHandler()
{
	addKeyListener(new KeyAdapter()
	{
		public void keyPressed(KeyEvent e)
		{
			if (e.getKeyCode() == KeyEvent.VK_ESCAPE && isEscapeEnabled())
			{
				escape(e);
			}
		}
	});
}
 
Example 27
Source Project: blog-codes   Source File: mxRubberband.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new rubberband selection for the given graph component.
 * 
 * @param graphComponent Component that contains the rubberband.
 */
public mxRubberband(final mxGraphComponent graphComponent)
{
	this.graphComponent = graphComponent;

	// Adds the required listeners
	graphComponent.getGraphControl().addMouseListener(this);
	graphComponent.getGraphControl().addMouseMotionListener(this);

	graphComponent.addListener(mxEvent.AFTER_PAINT, new mxIEventListener()
	{

		public void invoke(Object source, mxEventObject evt)
		{
			paintRubberband((Graphics) evt.getProperty("g"));
		}

	});

	// Handles escape keystrokes
	graphComponent.addKeyListener(new KeyAdapter()
	{
		/**
		 * 
		 * @param e
		 * @return
		 */
		public void keyPressed(KeyEvent e)
		{
			if (e.getKeyCode() == KeyEvent.VK_ESCAPE
					&& graphComponent.isEscapeEnabled())
			{
				reset();
			}
		}
	});

	// LATER: Add destroy method for removing above listeners
}
 
Example 28
Source Project: PacketProxy   Source File: FilterComboBoxEditor.java    License: Apache License 2.0 5 votes vote down vote up
public FilterComboBoxEditor() {
	editor = new HintTextField("フィルタ文字列 (ex: request == example.com && type == image)");
	editor.addKeyListener(new KeyAdapter() {
		public void keyReleased(KeyEvent e) {
			caret = editor.getCaretPosition();
			fireActionEvent(editor.getText());
		}
	});
}
 
Example 29
Source Project: JavaGame   Source File: TerisClient.java    License: MIT License 5 votes vote down vote up
@Override
public void loadFrame() {
	super.loadFrame();
	addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			block.keyPressed(e);
		}
	});
}
 
Example 30
Source Project: JavaGame   Source File: Client.java    License: MIT License 5 votes vote down vote up
@Override
public void loadFrame() {
	super.loadFrame();
	
	addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			loader.keyPressed(e);
		}
	});
}