http://expert.csdn.net/Expert/topic/2303/2303573.xml?temp=.2948877

解决方案 »

  1.   

    要使用jscrollpane.getViewport().setPreferredSize(Dimension)方法
      

  2.   

    付代码package zsg.project.webprint;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: ZSG_OnLine</p>
     * @author zsg
     * @version 1.0
     */public class Applet1 extends JApplet {
      private boolean isStandalone = false;
      ppPanel panel = new ppPanel();
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public Applet1() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        this.setSize(new Dimension(400,300));
        this.getContentPane().add(panel, BorderLayout.CENTER);
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  //static initializer for setting look & feel
      static {
        try {
          //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        }
        catch(Exception e) {
        }
      }
    }class ppPanel extends JScrollPane {
      FontMetrics titleFM;
      Font titleFont;               //标题字体
      Font normalFont;              //正常字体
      Font labelFont;//标注字体  public ppPanel() {
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }  void jbInit() throws Exception {
        this.setLayout(null);
        titleFont = new Font("Simsun", 1, 16);
        normalFont = new Font("Serif", 0, 12);
        labelFont = new Font("Simsun", 1, 10);
        titleFM = this.getFontMetrics(titleFont);
      }  public void paintComponent(Graphics g)
      {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        drawHead(g2,new String[3]);
        drawBotton(g2);
      }  /**
       * 绘制头
       * @param g2
       */
      public void drawHead(Graphics2D g2,String headName[]){
        g2.draw3DRect(4,4,592,20,true);
      }  /**
       * 绘制尾
       * @param g2
       */
      public void drawBotton(Graphics2D g2){
        g2.drawString("现在时间:2003-09-27",12,200);
        String write ="签名:             ";
        g2.drawString(write,(this.getBounds().width-titleFM.stringWidth(write)),450);
      }}
      

  3.   

    class ppPanel extends JScrollPane ?
    这里不行啊
    改成:
    class ppPanel extends JPanel然后 改一下jbInit() 
     private void jbInit() throws Exception {
        this.setSize(new Dimension(400,300));
        JScrollPane jScrollPane = new JScrollPane(new ppPanel());
        jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000))
        this.getContentPane().add(panel, BorderLayout.CENTER);
      }
      

  4.   

    JScrollePanel不是为了直接在上面画图而产生的。
    楼主可以将一个JPanle加入JScrollePanel,在JPanel上画,然后设置它的大小就好了。
      

  5.   

    按照几位的说法《JScrollePanel不是为了直接在上面画图而产生的。
    楼主可以将一个JPanle加入JScrollePanel,在JPanel上画,然后设置它的大小就好了。》这么改过了,一样不管用。哪位实现了再告诉我
      

  6.   

    jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000))
    应该可以了啊
      

  7.   

    jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000))
    应该可以了啊
      

  8.   

    package zsg.project.webprint;import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: ZSG_OnLine</p>
     * @author zsg
     * @version 1.0
     */public class Applet1 extends JApplet {
      private boolean isStandalone = false;
      ppPanel panel = new ppPanel();
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public Applet1() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        this.setSize(new Dimension(400,300));
            JScrollPane jScrollPane = new JScrollPane(new ppPanel());
            jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000));
            this.getContentPane().add(panel, BorderLayout.CENTER);
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  //static initializer for setting look & feel
      static {
        try {
          //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        }
        catch(Exception e) {
        }
      }
    }class ppPanel extends JScrollPane {
      FontMetrics titleFM;
      Font titleFont;               //标题字体
      Font normalFont;              //正常字体
      Font labelFont;//标注字体  public ppPanel() {
        try {
          this.setSize(new Dimension(600,450));
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }  void jbInit() throws Exception {
        this.setLayout(null);
        titleFont = new Font("Simsun", 1, 16);
        normalFont = new Font("Serif", 0, 12);
        labelFont = new Font("Simsun", 1, 10);
        titleFM = this.getFontMetrics(titleFont);
      }  public void paintComponent(Graphics g)
      {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        drawHead(g2,new String[3]);
        drawBotton(g2);
      }  /**
       * 绘制头
       * @param g2
       */
      public void drawHead(Graphics2D g2,String headName[]){
        g2.draw3DRect(4,4,592,20,true);
      }  /**
       * 绘制尾
       * @param g2
       */
      public void drawBotton(Graphics2D g2){
        g2.drawString("现在时间:2003-09-27",12,200);
        String write ="签名:             ";
        g2.drawString(write,(this.getBounds().width-titleFM.stringWidth(write)),450);
      }}
      

  9.   

    你的问题是JScrollPane 没有加进Applet  private void jbInit() throws Exception {
        this.setSize(new Dimension(400,300));        JScrollPane jScrollPane = new JScrollPane(new ppPanel());
            jScrollPane.getViewport().add(panel);
            panel.setPreferredSize(new Dimension(1000,1000));
            this.getContentPane().add(jScrollPane, BorderLayout.CENTER);
      }
      

  10.   

    private void jbInit() throws Exception {
                this.setSize(new Dimension(400,300));
                JScrollPane jScrollPane = new JScrollPane(panel);
                panel.setPreferredSize(new Dimension(1000,1000));
                this.getContentPane().add(jScrollPane, BorderLayout.CENTER);
          }
      

  11.   

    wolfsquare(狼平方 Swing报表工人)  的方法是对的..