Eu estou fazendo uma classe pra imprir um JFrame, tah funcionando direito, a unica coisa q acontece é q a parte final da imagem, não imprime… como se tivesse uma margem inferior, ou se o tamanho da folha estivesse definido menor do que o da impressora… Alguém pode me ajudar?
package airport;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
/**
*
* @author Silvia
*/
public class Impressora extends JFrame implements Printable{
private JLabel map;
private JLabel titulo = new JLabel();
private JButton printButton = new JButton("Imprimir");
private JTextArea area1 = new JTextArea();
private JTextArea area2 = new JTextArea();
private JTextArea area3 = new JTextArea();
private JTable table;
private JTable tableTitleTop;
private String name;
private String vers;
private String data;
private String kind;
private String group;
private String dfs;
private String width;
private String height;
private Font f1 = new Font ("Arial", Font.BOLD , 8);
private Font f2 = new Font ("Arial", Font.PLAIN , 8);
private Font f3 = new Font ("Arial", Font.BOLD , 12);
private double topLat;
private double botLat;
private DecimalFormat duasCasas = new DecimalFormat();
private Metodos metodos;
public Impressora(String name, String vers, String data, String kind, String group, String dfs, String width, String height, JLabel map, double topLat, double botLat, Metodos metodos){
duasCasas.setMaximumFractionDigits(2);
duasCasas.setMinimumFractionDigits(2);
this.setSize(595, 720);
this.setLocation(0,0);
this.setLayout(null);
this.setBackground(Color.red);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setContentPane(new JDesktopPane());
this.getContentPane().setBackground(Color.white);
this.setVisible(true);
this.name=name;
this.vers=vers;
this.data=data;
this.kind=kind;
this.group=group;
this.dfs=dfs;
this.width= width;
this.height= height;
this.topLat=topLat;
this.botLat=botLat;
this.metodos=metodos;
titulo.setSize(150, 20);
titulo.setLocation(225, 30);
titulo.setVisible(true);
titulo.setText("Map Test - "+ name );
add(titulo);
area1.setSize(50,70);
area1.setVisible(true);
area1.setLocation(20,75);
area1.setBackground(Color.white);
area1.setFont(f1);
area1.setEditable(false);
area1.setText("Name: " + "\n"+
"Version: " + "\n"+
"Date: " + "\n"+
"Kind: " + "\n"+
"Group: " + "\n"+
"DFS: " + "\n"+
"Width: " + "\n"+
"Height: " + "\n");
add(area1);
area2.setSize(50,70);
area2.setVisible(true);
area2.setLocation(70,75);
area2.setBackground(Color.white);
area2.setFont(f2);
area2.setEditable(false);
area2.setText( name + "\n"+
vers + "\n"+
data + "\n"+
kind + "\n"+
group + "\n"+
dfs + "\n"+
width + "\n"+
height+ "\n");
add(area2);
table = new JTable(2+metodos.getDfs(), 6);
table.setRowHeight(15);
table.setSize(350, table.getRowHeight()*metodos.getDfs()+2*table.getRowHeight());
table.setLocation(150,75);
table.setFont(f2);
table.setBorder(BorderFactory.createLineBorder(Color.BLACK));
table.setDefaultRenderer(Object.class, new CellRenderer());
table.setValueAt("", 0, 0);
table.setValueAt("Longitude", 0, 1);
table.setValueAt("Top X", 0, 2);
table.setValueAt("Y", 0, 3);
table.setValueAt("Bottom X", 0, 4);
table.setValueAt("Y", 0, 5);
table.setValueAt("Latitude", 1,0);
table.setValueAt(metodos.latStr(metodos.convertedValues(metodos.getTopLat())), 1, 2);
table.setValueAt(metodos.latStr(metodos.convertedValues(metodos.getBotLat())), 1, 4);
for(int i=0;i<metodos.getDfs();i++){
int k=i+1;
int j=i+2;
table.setValueAt("Lon"+k,j,0);
table.setValueAt(metodos.giveToTableColumn1()[i]+" ", j, 1);
table.setValueAt(metodos.giveToTableColumn2()[i]+" ", j, 2);
table.setValueAt(metodos.giveToTableColumn3()[i]+" ", j, 3);
table.setValueAt(metodos.giveToTableColumn4()[i]+" ", j, 4);
table.setValueAt(metodos.giveToTableColumn5()[i]+" ", j, 5);
}
add(table);
this.map=map;
map.setLocation(97, 170);
map.setBorder(BorderFactory.createLineBorder(Color.BLACK));
map.setVisible(true);
map.validate();
add(map);
area3.setSize(200,70);
area3.setVisible(true);
area3.setLocation(20,645);
area3.setBackground(Color.white);
area3.setFont(f1);
area3.setEditable(false);
area3.setText( "data: ____/____/_____ conferido: _______________________" + "\n"+
"data: ____/____/_____ revisado: _______________________");
add(area3);
printButton.setSize(100, 20);
printButton.setLocation(260, 645);
printButton.setVisible(true);
printButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
imprime();
}
});// end class metodo
add(printButton);
}
public void imprime(){
printButton.setVisible(false);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(Impressora.this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {}
}
printButton.setVisible(true);
}
public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY()-15);
this.print(g);
return PAGE_EXISTS;
}
}
class CellRenderer extends DefaultTableCellRenderer {
public CellRenderer() {
super();
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if ((row % 2) == 0) {
super.setBackground(Color.WHITE);
} else {
super.setBackground(new Color(235, 237, 239));
}
if(row==0){
super.setHorizontalAlignment(SwingConstants.CENTER);
}
else if(column ==0){
super.setHorizontalAlignment(SwingConstants.LEFT);
}
else{
super.setHorizontalAlignment(SwingConstants.RIGHT);
}
return super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
}
}