下面的打印按钮显示打印机选择窗口,但它不打印任何内容...但 JTable 包含数据
print_button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
try {
boolean complete = table2.print();
if (complete) {
JOptionPane.showMessageDialog(null, "Done printing");
} else {
JOptionPane.showMessageDialog(null, "printing.....");
}
} catch (PrinterException pe) {
}
}});
最佳答案
您需要为 JTable
提供大小才能打印:
table2.setSize(table2.getPreferredSize());
它有数据是正确的,但它需要有一个大小才能打印。
关于java - java中的print方法不打印jtable的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870392/