Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Add scrollbar to JTextArea

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-03-2010
Member
 
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.

Reply With Quote
  #2  
Old 10-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 10-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 10-03-2010
Member
 
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);
Reply With Quote
  #5  
Old 10-03-2010
Member
 
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);
Reply With Quote
  #6  
Old 10-03-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Add scrollbar to JTextArea"
Thread Thread Starter Forum Replies Last Post
Scrollbar Settings Bear 55 Customize Desktop 3 18-11-2010 04:05 AM
JTextArea for input text from the user liatB Software Development 1 17-03-2010 08:37 PM
JTextArea class of java Ram Bharose Software Development 5 13-02-2010 10:06 AM
Bolding text in a JTextArea Kieran Blenkarne Software Development 3 09-11-2009 12:10 PM
How to hide the Scrollbar in Frame Aamin Software Development 3 09-02-2009 05:46 PM


All times are GMT +5.5. The time now is 05:37 AM.