那位知道怎么将Graphics对象指定的图形缩小阿?

解决方案 »

  1.   

    g2.scale( (float)scale, (float)scale );
      

  2.   

    g2是指什么对象啊?Graphics还是Graphics2D?
      

  3.   

    再问一个问题:
    下面是我写的一个JBUTTON的事件处理方法,用于实现打印功能,可执行有点问题,JBUILDER提示类型转换异常。为什么不能将超类对象显示转换为子类对象,不是向下转换吗(down-cast)??? public void jButtonGDPrint_actionPerformed(ActionEvent e) {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Properties props = new Properties();
        props.put("awt.print.printer", "durango");
        props.put("awt.print.numCopies", "2");
        if (kit != null) {
          PrintJob printJob = kit.getPrintJob(this, "print", props);
          if (printJob != null) {
            Graphics pg = printJob.getGraphics();
            Graphics2D g2 = (Graphics2D) pg;          //执行时这行出错,类型转换异常
            PageFormat pf = new PageFormat();
            g2.translate(pf.getImageableX(), pf.getImageableY());
            if (pg != null) {
                try {
                  this.jScrollPaneGDay.printAll(pg);
                }
                finally {
                  pg.dispose();
                }
            }
            printJob.end();
          }
        }
      }
      

  4.   

    是Graphics2D。我打印用PrinterJob,不是PrintJob,转型没有出现过异常,你可以用PrinterJob试试。       PrinterJob printJob = PrinterJob.getPrinterJob();
          
              printJob.setPageable(makeInvoiceBook());
             
              if (printJob.printDialog())
              {  
              try
                 {  
                 printJob.print();
                 }
                 catch (Exception exception)
                 {  
                 JOptionPane.showMessageDialog(this, exception);
                 }
              }
    class Canvas implements Printable
    {
        public int print( Graphics g, PageFormat pf, int page )
           throws PrinterException
        {  
        Graphics2D g2 = (Graphics2D)g;
    ...
    }
    }
      

  5.   

    还有一个问题:我是将整个界面作为图形打印出来,用PrinterJob可以吗?
    有其他方法将JTABLE中的数据打印出来了吗?不用上述方法