简体   繁体   English

Java画图方法显示错误

[英]Java paint method show error

I am working in swing based project I want to print JTable . 我正在基于秋千的项目中工作,我想打印JTable For this purpose when I write print method like (tb1.print(JTable.printMode.Normal,header,footer)) it show error that (method paint cannot be applied to given type and required Graphics and also found printMode,MessageFormat,MessageFormat) while i cannot found PrintMode , MessageFormat etc now guide me where i found such type of format while my net-bean only show print (Graphics) or print(Graphics all) ? 为此,当我编写类似(tb1.print(JTable.printMode.Normal,header,footer))打印方法时(tb1.print(JTable.printMode.Normal,header,footer))它显示错误(无法将方法绘画应用于给定的类型和所需的图形,并且还找到了printMode,MessageFormat,MessageFormat)虽然我找不到PrintModeMessageFormat等现在可以指导我在哪里找到了这种类型的格式,而我的net-bean只显示print (Graphics)print(Graphics all) Here is my code. 这是我的代码。

import java.awt.event.KeyEvent;
import java.text.MessageFormat.*;
import javax.swing.JTable;
import java.text.*;
import javax.print.attribute.*; 

public class Printing extends javax.swing.JPanel {
 public Printing() {
  initComponents();
 }

 private void tb1ActionPerformed(java.awt.event.ActionEvent evt) {
  MessageFormat header = new MessageFormat("dd");
  MessageFormat footer = new MessageFormat("Page(0,number,integer)");
  try {
   tb1.paint(JTable.PrintMode.FIT_WIDTH, footer, header);
  } catch (Exception e) {
   System.err.format("Can not print %%n", e.getMessage()); 
  }
 }

 public static void main(String[] args) {
  java.awt.EventQueue.invokeLater(new Runnable() {
   public void run() {
    new Printing().setVisible(true);
   }
  });
 }       

tb1.paint(JTable.PrintMode.FIT_WIDTH, footer, header); isn't tb1.print(JTable.PrintMode.FIT_WIDTH, footer, header); 不是tb1.print(JTable.PrintMode.FIT_WIDTH, footer, header);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM