Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTextArea Indenting

843804Jan 21 2005 — edited Jan 21 2005
I am fairly new to swing and I'm trying to make a text editor. One of the features i want to implement is a TAB and Shift+TAB indent feature. What I mean by this is the user selects a few lines and hits the tab key and indents the lines with the textArea.tabSize or vice versa with shift+tab. I already got the JTextArea to recognize tab and shift tab with this code (from another post):

InputMap im = textArea1.getInputMap();
KeyStroke tab = KeyStroke.getKeyStroke("TAB");
textArea1.getActionMap().put(im.get(tab), new TabAction(true));
KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
im.put(shiftTab, shiftTab);
textArea1.getActionMap().put(im.get(shiftTab), new TabAction(false));

and obviously implementing the class TabAction. Inserting the tab isn't that difficult I use the Element class to get the lines position and insert 8 spaces or whatever its set to. My question is how can i get the shift+tab part to work obviously i will have to check if a tab exists on each line and then remove it.

Any sample code or ideas would be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2005
Added on Jan 21 2005
1 comment
369 views