我抄了一个可以预览的打印稍微改了一下!这个程序是打印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程序
最新推荐文章于 2023-11-22 09:57:02 发布