避免在按Tab键时删除选定的文本内容. [英] Avoiding deletion of selected text contents during tab key press.
问题描述
我创建了一个Java应用程序,其中JTextpane被用作编辑器.现在的问题是,当我选择一个文本块并按Tab键时,它会自动删除所选的文本内容.我不希望我的工具的编辑器出现这些行为.我需要将选定文本的内容添加到编辑器中,就像在notepad ++中一样.我该如何解决这个问题?谁能帮助我..我无法解决..请帮助..在此先感谢...
I have created a java application in which JTextpane is used as an editor. Now my problem is that when I select a block of text and press tab key, it automatically deletes the selected text contents. I don''t expect these behaviour for my tool''s editor. I need to add indendation of selected text to my editor just like in notepad++. How can I resolve this problem? Can any one please help me.. I am not able to resolve it.. Please help.. Thanks in advance...
推荐答案
- 选择了某些文本范围的事件应该很容易获得,并且应该被存储.
- 在按键/按键中事件处理程序您检查是否有一个选定的范围(上面已存储了该范围)
- 如果在选择文本时按下 tab键已取消,并且已执行适当的操作,就像您对标记行进行缩进一样.
- The event that some range of text was selected should be readily available and shall be stored.
- In the keydown / keypress event handler you check if there is a range selected (which was memorized above)
- If the tab key was pressed while text was selected the event is cancelled and the appropriate action is taken, like for you doing the indentation of the marked lines.
您所需要知道的就是如何为Java控件进行事件处理,这应该就差不多了.选择文本时取消keydown/keypress事件将使文本不会被擦除,但是您将能够检测到这种情况并采取相应的措施.
问候
All you have to know is how to do event handling for your java control and that should be pretty much it. Cancelling the keydown/keypress event when text is selected will keep the text from getting erased, but you will be able to detect the scenario and act accordingly.
Regards,
这篇关于避免在按Tab键时删除选定的文本内容.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!