Example usage for javax.swing.text DefaultEditorKit readOnlyAction

List of usage examples for javax.swing.text DefaultEditorKit readOnlyAction

Introduction

In this page you can find the example usage for javax.swing.text DefaultEditorKit readOnlyAction.

Prototype

String readOnlyAction

To view the source code for javax.swing.text DefaultEditorKit readOnlyAction.

Click Source Link

Document

Name of the action to set the editor into read-only mode.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Use TextAction");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTextArea leftArea = new JTextArea();
    final JTextArea rightArea = new JTextArea();

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftArea),
            new JScrollPane(rightArea));
    splitPane.setDividerLocation(.5);/* w w w  .j  av a2  s .c o m*/

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    JMenu menu = new JMenu("Options");
    menuBar.add(menu);
    JMenuItem menuItem;

    Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction);
    menuItem = menu.add(readAction);
    menuItem.setText("Make read-only");
    Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction);
    menuItem = menu.add(writeAction);
    menuItem.setText("Make writable");
    menu.addSeparator();

    Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction);
    menuItem = menu.add(cutAction);
    menuItem.setText("Cut");
    Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction);
    menuItem = menu.add(copyAction);
    menuItem.setText("Copy");
    Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction);
    menuItem = menu.add(pasteAction);
    menuItem.setText("Paste");

    frame.add(splitPane, BorderLayout.CENTER);
    frame.setSize(400, 250);
    frame.setVisible(true);

}

From source file:UseActions.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Use TextAction");
    Container contentPane = frame.getContentPane();
    Dimension empty = new Dimension(0, 0);

    final JTextArea leftArea = new JTextArea();
    JScrollPane leftScrollPane = new JScrollPane(leftArea);
    leftScrollPane.setPreferredSize(empty);

    final JTextArea rightArea = new JTextArea();
    JScrollPane rightScrollPane = new JScrollPane(rightArea);
    rightScrollPane.setPreferredSize(empty);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);//from www .  j a v a 2  s  .  c  o m
    JMenu menu = new JMenu("Options");
    menuBar.add(menu);
    JMenuItem menuItem;

    Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction);
    menuItem = menu.add(readAction);
    menuItem.setText("Make read-only");
    Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction);
    menuItem = menu.add(writeAction);
    menuItem.setText("Make writable");

    menu.addSeparator();

    Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction);
    menuItem = menu.add(cutAction);
    menuItem.setText("Cut");
    Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction);
    menuItem = menu.add(copyAction);
    menuItem.setText("Copy");
    Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction);
    menuItem = menu.add(pasteAction);
    menuItem.setText("Paste");

    contentPane.add(splitPane, BorderLayout.CENTER);
    frame.setSize(400, 250);
    frame.setVisible(true);
    splitPane.setDividerLocation(.5);
}