List of usage examples for javax.swing.text Utilities getWordEnd
public static final int getWordEnd(JTextComponent c, int offs) throws BadLocationException
From source file:Main.java
public void actionPerformed(ActionEvent e) { JTextComponent comp = getTextComponent(e); if (comp == null) return;//from w ww. j av a 2s. c o m Document doc = comp.getDocument(); int start = comp.getSelectionStart(); int end = comp.getSelectionEnd(); try { int left = Utilities.getWordStart(comp, start); int right = Utilities.getWordEnd(comp, end); String word = doc.getText(left, right - left); doc.remove(left, right - left); doc.insertString(left, word.toUpperCase(), null); comp.setSelectionStart(start); comp.setSelectionEnd(end); } catch (Exception ble) { return; } }
From source file:Main.java
public void actionPerformed(ActionEvent e) { JTextComponent comp = getTextComponent(e); if (comp == null) return;// ww w. j a v a 2 s.co m Document doc = comp.getDocument(); int start = comp.getSelectionStart(); int end = comp.getSelectionEnd(); try { int left = Utilities.getWordStart(comp, start); int right = Utilities.getWordEnd(comp, end); String word = doc.getText(left, right - left); doc.remove(left, right - left); doc.insertString(left, word.toUpperCase(), null); comp.setSelectionStart(start); comp.setSelectionEnd(end); } catch (BadLocationException ble) { return; } }