我抄了一个可以预览的打印稍微改了一下!这个程序是打印table的数据的!不知道合适你不!有四个类分别是MakeJbook ,Mainstart,PrintPreviewCanvas,PrintPreviewDialog。
public class PrintPreviewDialog extends JDialog {
class Scale extends Object {
private double value;
public Scale(double value)
{
this.value = value;
}
public final String toString()
{
return (int) (value * 100) + "%";
}
public final double getValue()
{
return value;
}
}
public PrintPreviewDialog(JDialog jd,String title,boolean mt,Book b)
{
super(jd,title,mt);
layoutUI(b);
}
public void layoutUI(Book book)
{
setSize(WIDTH, HEIGHT);
Container contentPane = getContentPane();
canvas = new PrintPreviewCanvas(book);
contentPane.add(new JScrollPane(canvas), BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
JButton nextButton = new JButton("下一页");
buttonPanel.add(nextButton);
nextButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
canvas.flipPage(1);
}
});
JButton previousButton = new JButton("上一页");
buttonPanel.add(previousButton);
previousButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
canvas.flipPage(-1);
}
});
JButton closeButton = new JButton("Close");
buttonPanel.add(closeButton);
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
dispose();
}
});
final JComboBox scaleChoice = new JComboBox();
scaleChoice.setEditable(false);
scaleChoice.addItem(new Scale(2));
scaleChoice.addItem(new Scale(1.5));
scaleChoice.addItem(new Scale(1.0));
scaleChoice.addItem(new Scale(0.75));
scaleChoice.addItem(new Scale(0.5));
scaleChoice.addItem(new Scale(0.25));
scaleChoice.setSelectedIndex(2) ;
scaleChoice.addItemListener(new ItemListener() {
可以预览的打印的Java程序
最新推荐文章于 2024-06-29 07:45:00 发布
这篇博客介绍了一个使用Java编写的打印预览程序,该程序能够预览并打印表格数据。程序包括四个类:MakeJbook、Mainstart、PrintPreviewCanvas和PrintPreviewDialog。PrintPreviewDialog类用于显示预览对话框,PrintPreviewCanvas类负责绘制预览页面,Mainstart类包含了主程序的启动逻辑,而MakeJbook类用于构建要打印的内容。程序支持缩放、翻页和关闭等操作,适用于表格数据的打印需求。
摘要由CSDN通过智能技术生成