Results 1 to 5 of 5
  1. #1
    Kyle227's Avatar
    Kyle227 is offline Member
    Join Date
    Apr 2010
    Location
    Mass
    Posts
    47
    Rep Power
    0

    Question Console like Environment in JTextArea

    I have a couple of questions. I want to make a console like environment in a JTextArea like the command prompt or terminal. Like when you type in the terminal you can only type on the last line and cant move the mouse cursor up and delete any characters. For example in the terminal the mouse cursor always stays after the line name@name-linux:~$ You cant change the mouse cursor position with the mouse. Is that even possible. My second question is can you change the text color in the JTextArea only on some text. Like this

    This is some text
    This is some text
    This is some more text

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    For your first problem, I'd probably use two different text areas- one for what's currently being typed, and one for the "history".

    For your second problem, read this: Using Text Components (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Kyle227's Avatar
    Kyle227 is offline Member
    Join Date
    Apr 2010
    Location
    Mass
    Posts
    47
    Rep Power
    0

    Default

    Thanks Kevin but Im still having some problems. Im going to be using JTextPane. So you want me to create two JTextPanes. One is the history and the other is the enter text in. This is going to be hard to explain. So do I want my enter text TextPane to be below the history TextPane? When I press enter in the enter text TextPane the text will go to the history TextPane. The history textpane will get bigger and bigger as I add more text to it and it will push the enter text textpane down. Then when I clear it, the enter text TextPane will be back at the top and there will be nothing in the history TextPane. Is that correct?

    Also Im having trouble with added colors to some of the text in a JTextPane. Do you have to use StyleContext or something like that?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Quote Originally Posted by Kyle227 View Post
    Thanks Kevin but Im still having some problems. Im going to be using JTextPane. So you want me to create two JTextPanes. One is the history and the other is the enter text in. This is going to be hard to explain. So do I want my enter text TextPane to be below the history TextPane? When I press enter in the enter text TextPane the text will go to the history TextPane. The history textpane will get bigger and bigger as I add more text to it and it will push the enter text textpane down. Then when I clear it, the enter text TextPane will be back at the top and there will be nothing in the history TextPane. Is that correct?
    Well, what happened when you tried that? Sounds about right to me.

    Quote Originally Posted by Kyle227 View Post
    Also Im having trouble with added colors to some of the text in a JTextPane. Do you have to use StyleContext or something like that?
    If you want help with colors, you should provide an SSCCE that demonstrates what you're doing. Also, just as a hint, you might try using HTML to add colors.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Kyle227's Avatar
    Kyle227 is offline Member
    Join Date
    Apr 2010
    Location
    Mass
    Posts
    47
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    Well, what happened when you tried that? Sounds about right to me.
    Well I didn't really do that yet, I was making sure I was going to do it right. Out of all the things I know about java, GUI are one of the things that I have trouble in.:mad: Sorry but I don't know how to auto resize a component. Is there a setting for that or do I right custom code for that. So far I added two JTextPane to my JFrame. I will worry about the colors later. Thanks:)

Similar Threads

  1. Need help with printing console output to JTextArea
    By ShinTec in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2010, 10:10 AM
  2. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  3. Replies: 1
    Last Post: 12-13-2008, 01:24 AM
  4. Environment for java
    By carl in forum New To Java
    Replies: 2
    Last Post: 07-31-2007, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •