解决方案 »

  1.   

    怎么没人回复.随便写了下.不要见笑..
    package com.test;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;@SuppressWarnings("serial")
    public class Demo001 extends JFrame implements ActionListener
    {
    public static void main(String[] args) { 
    @SuppressWarnings("unused")
    Demo001 demo001=new Demo001();


    public static int jspValue;
    JScrollPane jsp=null;
    JTextArea jta=null;
    JPanel jp=null;
    JButton jb1=null;
    JButton jb2=null;
    public Demo001()
    {
    jta=new JTextArea();
    jta.setLineWrap(true);
    jsp=new JScrollPane(jta);
    jp=new JPanel();
    jb1=new JButton("上");
    jb2=new JButton("下");
    jp.add(jb1);
    jp.add(jb2);
    this.setLayout(new BorderLayout());
    this.add(jsp);
    this.add(jp,BorderLayout.SOUTH);
    jb1.addActionListener(this);
    jb2.addActionListener(this);
    this.setSize(300, 200);
    this.setVisible(true);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    @Override
    public void actionPerformed(ActionEvent e) { if(e.getSource()==jb2)
    {
    jspValue=jsp.getVerticalScrollBar().getValue();
    jsp.getVerticalScrollBar().setValue(jspValue+=jsp.getHeight());

    }
    else if(e.getSource()==jb1)
    {
    jspValue=jsp.getVerticalScrollBar().getValue();
    jsp.getVerticalScrollBar().setValue(jspValue-=jsp.getHeight());
    }
    }
    }