Here you can find the source of selectionToUpperCase(JTextComponent textPane)
public static void selectionToUpperCase(JTextComponent textPane)
//package com.java2s; //License from project: Apache License import javax.swing.text.JTextComponent; public class Main { public static void selectionToUpperCase(JTextComponent textPane) { int start = textPane.getSelectionStart(); int end = textPane.getSelectionEnd(); if (Math.abs(start - end) > 0) { String upper = textPane.getSelectedText().toUpperCase(); textPane.replaceSelection(upper); textPane.setCaretPosition(start); textPane.moveCaretPosition(end); }/*from ww w . j av a2s. c o m*/ } }