Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Swing
I have created one JPanel to add JTextArea in that how to add Both Scrollbar to JTextArea...using manually not using any IDE's
Posted 5-Sep-12 9:17am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check whether the below code is what you need or let me know if your requirement is different.
 
 
import java.awt.Dimension;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
 
public class TextAreaExample extends JFrame {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = -116021326175824941L;
	private JScrollPane jScrollPane1;
	private JTextArea textArea;
 
	public TextAreaExample() {
		this.setPreferredSize(new Dimension(360,200	));
		
		textArea = new JTextArea(8,30);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		
		jScrollPane1 = new JScrollPane(textArea);
		
		jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		JPanel panel = new JPanel();
		panel.setSize(200, 200);
		panel.add(jScrollPane1);
		getContentPane().add(panel);
		pack();
	}
 
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				UIManager.put("swing.boldMetal", Boolean.FALSE);
				new TextAreaExample().setVisible(true);
			}
		});
	}
 
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 Kornfeld Eliyahu Peter 407
2 Maciej Los 369
3 DamithSL 221
4 OriginalGriff 218
0 OriginalGriff 6,383
1 DamithSL 4,879
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,056
4 Sergey Alexandrovich Kryukov 3,927


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100