简体   繁体   中英

Java paint method show error

I am working in swing based project I want to print 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) ? 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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