Results 1 to 6 of 6

Thread: Add scrollbar to JTextArea

  1. #1
    Join Date
    Mar 2010
    Posts
    200

    Add scrollbar to JTextArea

    Hello,
    I made a GUI application with a JTextArea, when i append some text to it, it begin change its height, now I want to add scrollbar to the Jtextarea, but I do not know how to do that. If you have any idea please let me know. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Add scrollbar to JTextArea

    Hello,
    "now I want to add scrollbar to the Jtextarea, but I do not know how to do that. If you have any idea please let me know."
    The solution for your problem is to add a JScrollPane to your JTextArea. I think this is quite simple solution and you should not have any problems to do it. Still if you have queries regarding this topic then you can post and we will try to solve it.

  3. #3
    Join Date
    Dec 2009
    Posts
    202

    Re: Add scrollbar to JTextArea

    Hello,
    Even I want to add a scrollbar to the Jtextarea, but I do not know how to code that. I have tried you solution but it does not work for me. I think if you post a sample source code it would be great and it can help me a lot than just a explanation. Also, if you have any other alternative then please let me know I am the interested here. Thanks in advance.

  4. #4
    Join Date
    Mar 2010
    Posts
    200

    Re: Add scrollbar to JTextArea

    Hello,
    This is my updated code have a look at it and if you find any more problems then please guide me with the correct.
    Code:
    JScrollPane scpn = new JScrollPane (informationRunwayEnglishTextField);
    
    contentPane.setPreferredSize (new Dimension (450, 110));
    contentPane.add (scpn, BorderLayout.CENTER);
    
    sp = new JScrollPane JScrollPane (informationRunwayEnglishTextField);
    spane.getVerticalScrollBar (). addAdjustmentListener (new myAction () (
    public void adjustmentValueChanged (AdjustmentEvent ae) (
    int val = ae.getValue ();
    String str = Integer.toString (val);
    field.setText (str);
    }
    });
    panelRunwayStatus.add (sp);

  5. #5
    Join Date
    Nov 2009
    Posts
    343

    Re: Add scrollbar to JTextArea

    Hello,
    You can take help of the following example, this is not the complete code, but will surely help you
    Code:
    TextArea txar = new JTextArea(5, 30);
    JScrollPane scpn = new JScrollPane(txar);
    ...
    contentPane.setPreferredSize(...);
    ...
    contentPane.add(scpn, BorderLayout.CENTER);

  6. #6
    Join Date
    Nov 2009
    Posts
    347

    Re: Add scrollbar to JTextArea

    Hello,
    If you need to add a scrollbar to the Jtextarea, then here is the code to do it. This is how you can add scrollbar to it
    Here is the code for the same
    Code:
    JScrollPane scpn = new JScrollPane(mainConsole);
    scpn.setBounds(10,50,760,520);
    scpn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    Hope the above will help you.

Similar Threads

  1. Scrollbar Settings
    By Bear 55 in forum Customize Desktop
    Replies: 3
    Last Post: 18-11-2010, 04:05 AM
  2. JTextArea for input text from the user
    By liatB in forum Software Development
    Replies: 1
    Last Post: 17-03-2010, 08:37 PM
  3. JTextArea class of java
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 10:06 AM
  4. Bolding text in a JTextArea
    By Kieran Blenkarne in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 12:10 PM
  5. How to hide the Scrollbar in Frame
    By Aamin in forum Software Development
    Replies: 3
    Last Post: 09-02-2009, 05:46 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
  •