Java Code Examples for javax.swing.JTextArea#addKeyListener()

The following examples show how to use javax.swing.JTextArea#addKeyListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DFDSNamePanel.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create the panel.
 */
public DFDSNamePanel(Engine engine, Element element) {
    super(new BorderLayout());
    this.engine = engine;
    this.element = element;
    dataPlugin = NDataPluginFactory.getExistingDataPlugin(engine);
    textArea = new JTextArea();
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setComponentPopupMenu(createSelectLanguageMenu());

    textArea.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (undoManager == null)
                return;
            if (e.isControlDown()) {
                if (e.getKeyCode() == KeyEvent.VK_Z)
                    if (undoManager.canUndo())
                        undoManager.undo();
                if (e.getKeyCode() == KeyEvent.VK_Y)
                    if (undoManager.canRedo())
                        undoManager.redo();
            }
        }
    });

    if (dataPlugin != null) {
        Row row = dataPlugin.findRowByGlobalId(element.getId());
        if (row instanceof Function) {
            Function function = (Function) row;
            panel = new ArrowLinksPanel(function);
            JSplitPane splitPane = new JSplitPane();
            add(splitPane, BorderLayout.CENTER);
            splitPane.setLeftComponent(new JScrollPane(textArea));
            splitPane.setRightComponent(panel);
            createChecker();
            return;
        }
    }

    add(new JScrollPane(textArea), BorderLayout.CENTER);

    createChecker();
}
 
Example 2
Source File: DatabaseManagerSwing.java    From evosql with Apache License 2.0 4 votes vote down vote up
private void initGUI() {

        JPanel pCommand = new JPanel();

        pResult = new JPanel();
        nsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pCommand,
                                     pResult);

        // Added: (weconsultants@users)
        nsSplitPane.setOneTouchExpandable(true);
        pCommand.setLayout(new BorderLayout());
        pResult.setLayout(new BorderLayout());

        Font fFont = new Font("Dialog", Font.PLAIN, 12);

        txtCommand = new JTextArea(7, 40);

        txtCommand.setMargin(new Insets(5, 5, 5, 5));
        txtCommand.addKeyListener(this);

        txtCommandScroll = new JScrollPane(txtCommand);
        txtResult        = new JTextArea(25, 40);

        txtResult.setMargin(new Insets(5, 5, 5, 5));

        txtResultScroll = new JScrollPane(txtResult);

        txtCommand.setFont(fFont);
        txtResult.setFont(new Font("Courier", Font.PLAIN, 12));
        pCommand.add(txtCommandScroll, BorderLayout.CENTER);

        gResult = new GridSwing();

        TableSorter sorter = new TableSorter(gResult);

        tableModel   = sorter;
        gResultTable = new JTable(sorter);

        sorter.setTableHeader(gResultTable.getTableHeader());

        gScrollPane = new JScrollPane(gResultTable);

        gResultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        gResult.setJTable(gResultTable);

        //getContentPane().setLayout(new BorderLayout());
        pResult.add(gScrollPane, BorderLayout.CENTER);

        // Set up the tree
        rootNode    = new DefaultMutableTreeNode("Connection");
        treeModel   = new DefaultTreeModel(rootNode);
        tTree       = new JTree(treeModel);
        tScrollPane = new JScrollPane(tTree);

        // System.out.println("Adding mouse listener");
        tTree.addMouseListener(this);
        tScrollPane.setPreferredSize(new Dimension(200, 400));
        tScrollPane.setMinimumSize(new Dimension(70, 100));
        txtCommandScroll.setPreferredSize(new Dimension(560, 100));
        txtCommandScroll.setMinimumSize(new Dimension(180, 100));
        gScrollPane.setPreferredSize(new Dimension(460, 300));

        ewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tScrollPane,
                                     nsSplitPane);

        // Added: (weconsultants@users)
        ewSplitPane.setOneTouchExpandable(true);
        fMain.getContentPane().add(ewSplitPane, BorderLayout.CENTER);

        // Added: (weconsultants@users)
        jStatusLine = new JLabel();
        iReadyStatus =
            new JButton(new ImageIcon(CommonSwing.getIcon("StatusReady")));

        iReadyStatus.setSelectedIcon(
            new ImageIcon(CommonSwing.getIcon("StatusRunning")));

        pStatus = new JPanel();

        pStatus.setLayout(new BorderLayout());
        pStatus.add(iReadyStatus, BorderLayout.WEST);
        pStatus.add(jStatusLine, BorderLayout.CENTER);
        fMain.getContentPane().add(pStatus, "South");
        doLayout();

        if (fMain instanceof java.awt.Window) {
            ((java.awt.Window) fMain).pack();
        } else {
            ((Container) fMain).validate();
        }
    }
 
Example 3
Source File: InputDialog.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
  * Prompt and return input.
  *
  * @param title       the title of the dialog.
  * @param description the dialog description.
  * @param icon        the icon to use.
  * @param parent      the parent to use.
  * @return the user input.
  */
 public String getInput(String title, String description, Icon icon, Component parent) {
     textArea = new JTextArea();
     textArea.setLineWrap(true);

     TitlePanel titlePanel = new TitlePanel(title, description, icon, true);

     // Construct main panel w/ layout.
     final JPanel mainPanel = new JPanel();
     mainPanel.setLayout(new BorderLayout());
     mainPanel.add(titlePanel, BorderLayout.NORTH);

     // The user should only be able to close this dialog.
     final Object[] options = {Res.getString("ok"), Res.getString("cancel")};
     optionPane = new JOptionPane(new JScrollPane(textArea), JOptionPane.PLAIN_MESSAGE,
         JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);

     mainPanel.add(optionPane, BorderLayout.CENTER);

     // Lets make sure that the dialog is modal. Cannot risk people
     // losing this dialog.
     JOptionPane p = new JOptionPane();
     dialog = p.createDialog(parent, title);
     dialog.setModal(true);
     dialog.pack();
     dialog.setSize(width, height);
     dialog.setContentPane(mainPanel);
     dialog.setLocationRelativeTo(parent);
     optionPane.addPropertyChangeListener(this);

     // Add Key Listener to Send Field
     textArea.addKeyListener(new KeyAdapter() {
         @Override
public void keyPressed(KeyEvent e) {
             if (e.getKeyChar() == KeyEvent.VK_TAB) {
                 optionPane.requestFocus();
             }
             else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                 dialog.dispose();
             }
         }
     });

     textArea.requestFocus();
     textArea.setWrapStyleWord(true);


     dialog.setVisible(true);
     return stringValue;
 }
 
Example 4
Source File: InputTextAreaDialog.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
  * Prompt and return input.
  *
  * @param title       the title of the dialog.
  * @param description the dialog description.
  * @param icon        the icon to use.
  * @param parent      the parent to use.
  * @return the user input.
  */
 public String getInput(String title, String description, Icon icon, Component parent) {
     textArea = new JTextArea();
     textArea.setLineWrap(true);

     TitlePanel titlePanel = new TitlePanel(title, description, icon, true);

     // Construct main panel w/ layout.
     final JPanel mainPanel = new JPanel();
     mainPanel.setLayout(new BorderLayout());
     mainPanel.add(titlePanel, BorderLayout.NORTH);

     // The user should only be able to close this dialog.
     final Object[] options = {Res.getString("ok"), Res.getString("cancel")};
     optionPane = new JOptionPane(new JScrollPane(textArea), JOptionPane.PLAIN_MESSAGE,
             JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);

     mainPanel.add(optionPane, BorderLayout.CENTER);

     // Let's make sure that the dialog is modal. Cannot risk people
     // losing this dialog.
     JOptionPane p = new JOptionPane();
     dialog = p.createDialog(parent, title);
     dialog.setModal(true);
     dialog.pack();
     dialog.setSize(width, height);
     dialog.setContentPane(mainPanel);
     dialog.setLocationRelativeTo(parent);
     optionPane.addPropertyChangeListener(this);

     // Add Key Listener to Send Field
     textArea.addKeyListener(new KeyAdapter() {
         @Override
public void keyPressed(KeyEvent e) {
             if (e.getKeyChar() == KeyEvent.VK_TAB) {
                 optionPane.requestFocus();
             }
             else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                 dialog.dispose();
             }
         }
     });

     textArea.requestFocus();


     dialog.setVisible(true);
     return stringValue;
 }