{filelink=904}
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.print.PrinterException;
public class ImprimerTable {
public ImprimerTable()
{
try
{
String[] colonnes = { "Nom", "Fonction" };
Object lignes[][] = {
{ "Bernard A.", "Dir. Tech"},
{ "Alber. Sin", "Dir. Financier"},
{ "Steven Cat", "Chef Projet Info"},
{ "Nicolas Lambert", "Resp. tech"}
};
JTable table = new JTable(lignes, colonnes);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jPanel = new JPanel(new GridLayout(2, 0));
jPanel.setOpaque(true);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
jPanel.add(new JScrollPane(table));
frame.add(jPanel);
frame.pack();
frame.setVisible(true);
// Imprimer la table
table.print();
}catch(Exception err)
{
err.printStackTrace();
}
}
public static void main(String[] args)
{
new ImprimerTable();
}
}