Java Tutorial/SWT/StyledText Action

Материал из Java эксперт
Перейти к: навигация, поиск

Clear any key bindings

pass SWT.NULL for the action. For example, to remove the preceding insert/overwrite toggle, use this code:



styledText.setKeyBinding("i" | SWT.ALT, SWT.NULL);





Get the action bound to Alt+E

int altEAction = styledText.getKeyBinding("e" | SWT.ALT);





Key Binding Actions from the StyledText Class

ConstantDescriptionstatic int COLUMN_NEXTMoves the caret to the next column.static int COLUMN_PREVIOUSMoves the caret to the previous column.static int COPYCopies the currently selected text to the clipboard.static int CUTCuts the currently selected text to the clipboard.static int DELETE_NEXTDeletes the next character.static int DELETE_PREVIOUSDeletes the previous character.static int DELETE_WORD_NEXTDeletes the next word.static int DELETE_WORD_PREVIOUSDeletes the previous word.static int LINE_DOWNMoves the caret down one line.static int LINE_ENDMoves the caret to the end of the current line.static int LINE_STARTMoves the caret to the start of the current line.static int LINE_UPMoves the caret up one line.static int PAGE_DOWNMoves the caret down one page.static int PAGE_UPMoves the caret up one page.static int PASTEPastes the text from the clipboard to the current caret position.static int SELECT_COLUMN_NEXTSelects the character in the next column and moves the caret to the next column.static int SELECT_COLUMN_PREVIOUSSelects the character in the previous column and moves the caret to the previous column.static int SELECT_LINE_DOWNMoves the caret down one line, selecting the text between the previous caret position and the new caret position.static int SELECT_LINE_ENDMoves the caret to the end of the current line, selecting the text between the previous caret position and the new caret position.static int SELECT_LINE_STARTMoves the caret to the start of the current line, selecting the text between the previous caret position and the new caret position.static int SELECT_LINE_UPMoves the caret up one line, selecting the text between the previous caret position and the new caret position.static int SELECT_PAGE_DOWNMoves the caret down one page, selecting the text between the previous caret position and the new caret position.static int SELECT_PAGE_UPMoves the caret up one page, selecting the text between the previous caret position and the new caret position.static int SELECT_TEXT_ENDMoves the caret to the end of the text, selecting the text between the previous caret position and the new caret position.static int SELECT_TEXT_STARTMoves the caret to the start of the text, selecting the text between the previous caret position and the new caret position.static int SELECT_WINDOW_ENDMoves the caret to the end of the text currently displayed in the window, selecting the text between the previous caret position and the new caret position.static int SELECT_WINDOW_STARTMoves the caret to the start of the text currently displayed in the window, selecting the text between the previous caret position and the new caret position.static int SELECT_WORD_NEXTMoves the caret to the next word, selecting the text between the previous caret position and the new caret position.static int SELECT_WORD_PREVIOUSMoves the caret to the previous word, selecting the text between the previous caret position and the new caret position.static int TEXT_ENDMoves the caret to the end of the text.static int TEXT_STARTMoves the caret to the start of the text.static int TOGGLE_OVERWRITEToggles the insert/overwrite flag.static int WINDOW_ENDMoves the caret to the end of the text currently displayed in the window.static int WINDOW_STARTMoves the caret to the start of the text currently displayed in the window.static int WORD_NEXTMoves the caret to the next word.static int WORD_PREVIOUSMoves the caret to the previous word.


Passing a modifier constant isn"t necessary

int zAction = styledText.getKeyBinding("z");





Set a key binding

, call setKeyBinding() and pass both the key and the action. The possible values for the key are the same as for getKeyBinding(): characters or key constants from SWT, optionally bitwise ORed with modifier key constants. The possible values for the action are the constants from the ST class. For example, to bind the insert/overwrite toggle action to Alt+I, use this code



styledText.setKeyBinding("i" | SWT.ALT, ST.TOGGLE_OVERWRITE);