Swing . , , , , , Actions. :
class UpperCaseAction extends TextAction
{
public UpperCaseAction()
{
super("UpperCase");
}
public void actionPerformed(ActionEvent e)
{
JTextComponent component = getFocusedComponent();
int start = cmoponent.getSelectionStart();
int end = component.getSelectionEnd();
String replace = component.getSelectedText().toUpperCase();
component.replaceRange(replace, start, end);
}
}
, , . :
Action action = new UpperCaseAction();
JMenuItem menuItem = new JMenuItem( action );
JButton button = new JButton( action );