Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You do not need to create your own component.</p> <p>This can be done (as in I have done it) using a custom <a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/text/DocumentFilter.html" rel="noreferrer">DocumentFilter</a>.</p> <p>You can get the document from <code>textPane.getDocument()</code> and set a filter on it by <code>document.setFilter()</code>. Within the filter, you can check the prompt position, and only allow modifications if the position is after the prompt.</p> <p>For example:</p> <pre><code>private class Filter extends DocumentFilter { public void insertString(final FilterBypass fb, final int offset, final String string, final AttributeSet attr) throws BadLocationException { if (offset &gt;= promptPosition) { super.insertString(fb, offset, string, attr); } } public void remove(final FilterBypass fb, final int offset, final int length) throws BadLocationException { if (offset &gt;= promptPosition) { super.remove(fb, offset, length); } } public void replace(final FilterBypass fb, final int offset, final int length, final String text, final AttributeSet attrs) throws BadLocationException { if (offset &gt;= promptPosition) { super.replace(fb, offset, length, text, attrs); } } } </code></pre> <p>However, this prevents you from programmatically inserting content into the output (noneditable) section of the terminal. What you can do instead is either a passthrough flag on your filter that you set when you're about to add the output, or (what I did) set the document filter to null before appending the output, and then reset it when you're done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload