Home > Java > javaTutorial > Detailed explanation of JScrollPane scrolling panel instance in Java

Detailed explanation of JScrollPane scrolling panel instance in Java

巴扎黑
Release: 2017-09-08 09:53:25
Original
3858 people have browsed it

This article mainly introduces a brief introduction to the commonly used Java panel JScrollPane and a related example. Friends in need can refer to it.

When setting up the interface, you may encounter a situation where a larger part of the content is displayed in a smaller container form. In this case, you can use the JScrollPane panel.

The JScrollPane panel is a panel with scroll bars. It is also a container, but JScrollPane can only place one component and cannot use a layout manager. If you need to place multiple components on the JScrollPane panel, you need to place multiple components on the JPanel, and then add the JPanel panel as a whole component on the JScrollPane component. Everyone must pay attention to this! Below we use an example to understand its usage and techniques.

Source code:


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){
 @SuppressWarnings("unused")
		JscrollPaneDemo example=new JscrollPaneDemo(); 
 }
}
Copy after login

It is recommended that friends try not to copy the code during the learning process, but try to do it yourself, especially beginners. On the one hand, you can deepen your understanding, and on the other hand, you can also practice coding speed. As a programmer, you must not only have good programming habits and skills, but also have speed.

The above is the detailed content of Detailed explanation of JScrollPane scrolling panel instance in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template