Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35661

Re: JTextArea

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: JTextArea
Date 2016-09-27 17:44 +0000
Organization A noiseless patient Spider
Message-ID <nseb5v$apn$1@dont-email.me> (permalink)
References <76597439-1bdd-4674-bbc2-771e593ab06e@googlegroups.com> <a8e9f052-b06c-413b-886a-5ccb52089227@googlegroups.com> <nse0ke$ts8$1@dont-email.me> <4caa7450-ba80-4edd-8e05-3de4e668d350@googlegroups.com>

Show all headers | View raw


On Tue, 27 Sep 2016 08:28:31 -0700, Eric Douglas wrote:

> JTextArea extends JEditorPane,
>
No sir. According to the Java 8 documentation it extends JTextComponent, 
which subclasses  JEditorPane, JTextArea and JTextField.

> so since I am using the built in methods
> (ie insert(), setLineWrap(), setWrapStyleWord())
>
and also copy(), cut(), paste()... But these are really there for 
programmatic use, not for handling keyboard input. 

IIRC I built my terminal emulator with JTextArea rather than JEditorPane 
was because I needed access to keyboard input so I could send it to the 
host machine and EditorKit didn't provide that access. Its also possible 
that it insisted on scrolling, which would be inappropriate for a 
greenscreen emulator, but isn't for a text editor.


> also  it seems to me it would
> be a lot more trouble to extend JEditorPane.
> 
There's a lot of stuff I'd expect an editor to do, but would have to be 
handcoded into JTextArea, such as changing the cursor (referred to in 
JTextComponent docs as a 'caret') to indicate the current editor mode,
e.g. whether its in insert or overtype mode.


> Now, my next big problem is I'm trying to override the drag and drop
> behavior to accept text files, and currently if I drag and drop text
> within the JTextArea control the text just disappears if the drop
> location is in the range of the drag text.
> What am I missing there?
>
Well, speaking for myself, I'd first try using JEditorPane to see how 
close it is to my requirements it is 'out of the box'. 

Insertion of text files should be possible with either JTextArea or 
JEditPane by using the JTextComponent.replaceSelection() method. Both 
probably need a Menu action or a JButton to trigger the file insert (use 
JFileChooser to select the file, read it into a String, call 
replaceSelection() to either replace the selected text or do an insert at 
the caret).

IOW, whether you decide to use a JTextArea or JEditorPane will depend on 
the other stuff you need and whether *that* is already in JEditorPane 
already.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

JTextArea Eric Douglas <e.d.programmer@gmail.com> - 2016-09-27 05:11 -0700
  Re: JTextArea Eric Douglas <e.d.programmer@gmail.com> - 2016-09-27 05:19 -0700
    Re: JTextArea Martin Gregorie <martin@address-in-sig.invalid> - 2016-09-27 14:44 +0000
      Re: JTextArea Eric Douglas <e.d.programmer@gmail.com> - 2016-09-27 08:28 -0700
        Re: JTextArea Martin Gregorie <martin@address-in-sig.invalid> - 2016-09-27 17:44 +0000
          Re: JTextArea Eric Douglas <e.d.programmer@gmail.com> - 2016-09-27 14:00 -0700

csiph-web