java swing 之 JScrollPane(滚动面板)的使用
发布日期:2021-06-30 18:39:03 浏览次数:2 分类:技术文章

本文共 1293 字,大约阅读时间需要 4 分钟。

/** * java swing 之JScrollPane面板 * 在设置界面时,可能会遇到在一个较小的容器窗体中显示一个较大部分的内容,这时可以使用 * JScrollPane面板,JscrollPane面板是带滚动条的面板,也是一种容器,但是常用于布置单个 * 控件,并且不可以使用布局管理器。如果需要在JScrollPane面板中放置多个控件,需要将多个 * 控件放置到JPanel 面板上,然后将JPanel面板作为一个整体控件添加到JScrollPane控件上。 *  * @author gao */package com.gao;import java.awt.BorderLayout;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.border.EmptyBorder;public class JScrollPaneDemo extends JFrame{    private JPanel contentPane;     private JScrollPane scrollPane;    private JTextArea textArea;	public JScrollPaneDemo(){    	 contentPane=new JPanel();    	 contentPane.setBorder(new EmptyBorder(5,5,5,5));    	 contentPane.setLayout(new BorderLayout(0,0));    	 this.setContentPane(contentPane);    	 scrollPane=new JScrollPane();    	 contentPane.add(scrollPane,BorderLayout.CENTER);    	 textArea=new JTextArea();    	 //scrollPane.add(textArea);     	 scrollPane.setViewportView(textArea);    	 this.setTitle("滚动面板使用");    	 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    	 this.setBounds(100, 100, 250, 200);    	 this.setVisible(true);     }	public static void main(String []args){		JScrollPaneDemo example=new JScrollPaneDemo(); 	}}

文章转自:http://www.2cto.com/kf/201405/297419.html

转载地址:https://linqiarui.blog.csdn.net/article/details/51068447 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:使用SMTP命令发送邮件
下一篇:JScrollPane 添加到流式布局的有多个JButton的JPanel上,如何使水平拉伸保持流式布局特点,垂直加滚动条?

发表评论

最新留言

很好
[***.229.124.182]2024年04月17日 05时08分50秒