• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

creating a custom command prompt with java gui  RSS feed

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there.

im just wondering if this is possible.

like creating your own cmd for configuration for my app.

Procedures
• create a frame with a textarea on it.
• put the output stream to the text area
• text area accepts input but the prompt couldn't be deleted.

  C:\>                   cls
(undeletable) (deleteable)

• works really just like the CMD.

is it possible to make it with java gui?
 
Sheriff
Posts: 21716
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirement to mark parts of your text area content as read-only can be done using DocumentFilter. In short:
- get the Document from your JTextArea
- cast it to AbstractDocument (this cast is safe unless the JTextArea has a custom document)
- create a custom DocumentFilter subclass and instantiate it (perhaps an anonymous inner class will do)
- call setDocumentFilter on the document

The custom DocumentFilter is where the hard work is done. Override insertString to make sure you can't insert anything before your current prompt position. Override remove to make sure you can't remove anything before your current prompt position. Override replace to make sure you can't replace anything before your current prompt position.

That leaves one issue: the caret position. You don't want to have your cursor to be positioned before your current prompt position. Perhaps you can use a CaretListener for that. But resetting the caret position to the end (or at least after your current prompt position) may cause text highlighting (for copying data) to not work. These are things you need to consider.
 
Rancher
Posts: 3032
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple approach:



More complex approach:

Protected Text Component
 
Rob Spoor
Sheriff
Posts: 21716
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congratulations Rob. You just taught me something new
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!