public TextFieldDemo() { initComponents(); InputStream in = getClass().getResourceAsStream("content.txt"); try { textArea.read(new InputStreamReader(in), null); } catch (IOException e) { e.printStackTrace(); } hilit = new DefaultHighlighter(); painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR); textArea.setHighlighter(hilit); entryBg = entry.getBackground(); entry.getDocument().addDocumentListener(this); InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap am = entry.getActionMap(); im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION); am.put(CANCEL_ACTION, new CancelAction()); }