This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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: 21747
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: 3042
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple approach:



More complex approach:

Protected Text Component
 
Rob Spoor
Sheriff
Posts: 21747
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 are using a rototiller, you are doing it wrong. Even on this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!