JTextComponent: getActions() : JTextComponent « javax.swing « Java by API






JTextComponent: getActions()

  

//A simple TextAction example.

import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JTextArea;

public class Main {
  public static void main(String[] args) {
    JTextArea ta = new JTextArea();
    ta.setLineWrap(true);

    Action[] actions = ta.getActions();
    JMenuBar menubar = new JMenuBar();
    JMenu actionmenu = new JMenu("Actions");
    menubar.add(actionmenu);

    JMenu firstHalf = new JMenu("1st Half");
    JMenu secondHalf = new JMenu("2nd Half");
    actionmenu.add(firstHalf);
    actionmenu.add(secondHalf);

    int mid = actions.length / 2;
    for (int i = 0; i < mid; i++) {
      firstHalf.add(actions[i]);
    }
    for (int i = mid; i < actions.length; i++) {
      secondHalf.add(actions[i]);
    }

    // Show it . . .
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(ta);
    f.setJMenuBar(menubar);
    f.setSize(300, 200);
    f.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.JTextComponent.KeyBinding
2.JTextComponent: addCaretListener(CaretListener listener)
3.JTextComponent: getCaretPosition()
4.JTextComponent: getDocument()
5.JTextComponent: getHighlighter()
6.JTextComponent: getSelectedText()
7.JTextComponent: getText(int offs, int len)
8.JTextComponent: moveCaretPosition(int pos)
9.JTextComponent: print(MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintService service, PrintRequestAttributeSet attributes, boolean interactive)
10.JTextComponent: read(Reader in, Object desc)
11.JTextComponent: replaceSelection(String content)
12.JTextComponent: select(int selectionStart, int selectionEnd)
13.JTextComponent: setDocument(Document doc)
14.JTextComponent: setDragEnabled(boolean b)
15.JTextComponent: setFocusAccelerator(char aKey)
16.JTextComponent: setNavigationFilter(NavigationFilter filter)
17.JTextComponent: setSelectedTextColor(Color c)
18.JTextComponent: setSelectionColor(Color c)
19.JTextComponent: setSelectionEnd(int selectionEnd)
20.JTextComponent: setSelectionStart(int selectionStart)
21.JTextComponent: write(Writer out)