« panel添加滚动条+BorderLayout布局javascript 页面跳转 后退或前进 »

JScrollPane 例子


import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

public class JScrollPaneDemo extends JFrame {
 public JScrollPaneDemo(){
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setBounds(20,20,300,200);
  initControls();
  this.setVisible(true);
 }
 private void initControls(){
  JPanel p=new JPanel();
  p.setLayout(new BorderLayout());
  
  
  JPanel p1=new JPanel();
  p1.setLayout(new GridLayout(20, 20));
  JButton []b=new JButton[20];
     int b1 = 0;
     for (int i = 0; i < 20; i++) {
       for (int j = 0; j < 20; j++) {
         p1.add(new JButton("Button " + b1));
         ++b1;
       }
     }
     int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
     int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
     JScrollPane jsp = new JScrollPane(p1, v, h);
    
  p.add(jsp,BorderLayout.CENTER);
  

  this.add(p);
 }

 /**
  * @param args
  */
 public static void main(String[] args) {
  new JScrollPaneDemo();

 }

}
 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

网站目录

最近发表

最新评论及回复

文章归档

Search

Powered By Z-Blog 1.8 Terminator(beta) Build 71218 Designed by Michael

Copyright 0-9999 subin.org.cn Rights Reserved. 晋ICP备08000685号