This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes making a portion of a text component unselectable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "making a portion of a text component unselectable" Watch "making a portion of a text component unselectable" New topic
Author

making a portion of a text component unselectable

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
hi there...

i am seeking an advice of which JTextComponent to use in this situation..
im like emulating a command prompt... like


console> "commands here"
console> "more commands"


im wondering... which text component will help me best here..

and also, i wanted to know how to make it not to be highlighted. really just a command prompt.

i need suggestions. thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

I don't know it it's possible at all. You don't see just about every application with command entry functionality to use a separate text field (or combo box with the last X commands) for entry and a non-editable text area for output.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
Rob Prime wrote:I don't know it it's possible at all. You don't see just about every application with command entry functionality to use a separate text field (or combo box with the last X commands) for entry and a non-editable text area for output.


i see. thanks for this enlightenment.

all i've done so far is uneditable text area with key listeners to append inputs.



so far, that is about my stuff.

so i need appends to do inputs thru key listeners. now im stuck in implementing the backspace...


Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
You can add a DocumentFilter to the textarea's document. In the insertString and remove methods just check whether offset comes in the last line after the last \n.
Also you can add custom higlighter t prevent selection text portions. Or just add caret listener to check selection start and end and reset thm if the start!=end.

Regards,
Stas
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: making a portion of a text component unselectable