1 package net.suberic.util.swing; 2 3 import javax.swing.*; 4 import javax.swing.text.*; 5 import java.awt.event.KeyEvent ; 6 import java.awt.AWTKeyStroke ; 7 import java.awt.KeyboardFocusManager ; 8 import java.util.*; 9 10 13 public class EntryTextArea extends JTextArea { 14 15 boolean keysUpdated = false; 16 19 public EntryTextArea() { 20 super(); 21 } 22 23 26 public EntryTextArea(Document doc) { 27 super(doc); 28 updateFocusTraversalKeys(); 29 } 30 31 34 public EntryTextArea(Document doc, String text, int rows, int columns) { 35 super(doc, text, rows, columns); 36 updateFocusTraversalKeys(); 37 } 38 39 42 public EntryTextArea(int rows, int columns) { 43 super(rows, columns); 44 updateFocusTraversalKeys(); 45 } 46 47 50 public EntryTextArea(String text) { 51 super(text); 52 updateFocusTraversalKeys(); 53 } 54 55 58 public EntryTextArea(String text, int rows, int columns) { 59 super(text, rows, columns); 60 updateFocusTraversalKeys(); 61 } 62 63 66 protected void updateFocusTraversalKeys() { 67 if (! keysUpdated) { 68 keysUpdated=true; 69 Set forward = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); 70 71 Set newForward = new HashSet(forward); 72 newForward.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); 73 74 setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 75 newForward); 76 77 Set backward = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); 78 79 Set newBackward = new HashSet(backward); 80 newBackward.add(AWTKeyStroke.getAWTKeyStroke("shift pressed TAB")); 81 82 setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, 83 newBackward); 84 } 85 } 86 87 } 88 | Popular Tags |