在JPanel中添加JTextarea的方法是,如何为Horizo​​ndal和Vertical ScrollBar添加JScroll Pane [英] In a JPanel to add JTextarea in that how to add JScroll Pane for Horizondal and Vertical ScrollBar

查看:114
本文介绍了在JPanel中添加JTextarea的方法是,如何为Horizo​​ndal和Vertical ScrollBar添加JScroll Pane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个JPanel来添加JTextArea,该方法是如何不使用任何IDE手动将两个滚动条添加到JTextArea ...

推荐答案

检查下面的代码是否是您所需要的,或者如果您的要求不同,请告诉我.

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);
			}
		});
	}

}


这篇关于在JPanel中添加JTextarea的方法是,如何为Horizo​​ndal和Vertical ScrollBar添加JScroll Pane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆