1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public void impressionJtable(final JTable tableau, final String titre) {
imprimer_tableau = new JMenuItem(titre);
imprimer_tableau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
imprimer_tableau.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//Impression
Datetime date=new Datetime();
MessageFormat header = new MessageFormat(titre);
MessageFormat footer = new MessageFormat("Page {0,number,integer}"+" -Peofofo- Date impression : "+date.getDateAvecSlash());
try {
//tableau.print(JTable.PrintMode.FIT_WIDTH, header, footer);
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
//attr.add(OrientationRequested.LANDSCAPE);
//Marges à appliquer
int margeGauche = 7;
int margeDroite = 7;
int margeHaut = 12;
int margeBas = 7;
attr.add(new MediaPrintableArea(margeGauche, margeHaut, 210 - margeDroite - margeGauche, 297 - margeBas - margeHaut, MediaPrintableArea.MM));
tableau.print(JTable.PrintMode.FIT_WIDTH, header, footer, true, attr, true);
} catch (java.awt.print.PrinterException e1) {
System.err.format("Cannot print %s%n", e1.getMessage());
}
}
});
imprimer.add(imprimer_tableau);
} |
Partager