/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
Problemer med udskivning til printer
Fra : Brian


Dato : 07-05-05 11:43

Hej,

Jeg sidder og arbejder med at få udskrivet en JTable - og der giver meget
store problemer. Jeg har angivet noget kode nedenfor. Problemet er at jeg
ikke får udskrevet noget som helt til siden, men der bliver lavet en side -
er der en som kan se hvorfor?

Desuden kunne jeg godt tænkt mig at vide hvad Printable.PAGE_EXISTS og
Printable.NO_SUCH_PAGE kendetegner. Jeg ved at de hhv. er 0 og 1, men er det
en værdi som kendetegner om der er udskrevet en side, eller er der altid 0
og 1?

Jeg håber at der er en som vil hjælpe mig...

På forhånd tak

Brian



/*************************
public class Print implements ActionListener,Runnable,Printable
{
private Language lang;
private Thread PRINTThread;
private Graphics2D g2d = null;
private Sheet sheet;
private int lines_on_page = 74;
private int pages,totalRows,y;
private Firm firm;
private boolean headerPrinted = false;
private Font f;
private float
lineHeight,charWidth,cmaxName,cmaxAdress,cmaxDistrict,cmaxZip,cmaxPhone,cmaxCVR,maxWidth,colName,colAdress,colZip,colDistrict,colPhone,colCVR;
private Point autoScrol;

public Print()
{
}

public void actionPerformed(ActionEvent e)
{
Sheet mysheet = Sheet.instance();
if(!mysheet.isEmpty())
{
if (PRINTThread == null)
{
PRINTThread= new Thread(this, "PRINTThread");
PRINTThread.start();
}
}
else
{
lang = Language.instance();
new MsgBox(lang.getText("info"),lang.getText("noprint"),false);
}
}

public void run()
{
PrinterJob printJob = PrinterJob.getPrinterJob ();
if (printJob.printDialog())
{
try
{
Book book = new Book ();
PageFormat documentPageFormat = new PageFormat ();
documentPageFormat.setOrientation (PageFormat.PORTRAIT);
book.append (this,documentPageFormat);
printJob.setPageable (book);
printJob.print();
}
catch (Exception PrintException)
{
PrintException.printStackTrace();
PRINTThread = null;
}
PRINTThread = null;
}
}

private void printHeader(Graphics g,PageFormat pf)
{
sheet = Sheet.instance();
lang = Language.instance();
totalRows = sheet.getRowCount()+1;
pages = totalRows/lines_on_page;
f = new Font( "Arial", Font.PLAIN , 10 );
lineHeight = f.getSize2D();
charWidth = Float.parseFloat("7");

cmaxName = sheet.MaxNameLength();
cmaxAdress = sheet.MaxAdressLength();
cmaxDistrict = sheet.MaxDistrictLength();
cmaxZip = sheet.MaxZipLength();
cmaxPhone = sheet.MaxPhoneLength();
cmaxCVR = sheet.MaxCVRLength();
maxWidth = (cmaxName + cmaxAdress + cmaxDistrict + cmaxZip +
cmaxPhone + cmaxCVR) * charWidth;

colName = charWidth;
colAdress = colName + cmaxAdress * charWidth;
colZip = colAdress + cmaxZip * charWidth;
colDistrict = colZip + cmaxDistrict * charWidth;
colPhone = colDistrict + cmaxPhone * charWidth;
colCVR = colPhone + cmaxCVR * charWidth;
y = 16;
autoScrol = new Point(0,0);
//--- Create the Graphics2D object
g2d = (Graphics2D) g;
//--- Translate the origin to 0,0 for the top left corner
g2d.translate (pf.getImageableX(), pf.getImageableY());
//--- Set the drawing color to black
g2d.setPaint (Color.black);
g2d.setFont(f);
g2d.drawString(lang.getText("firm"), (int)(colName +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString (lang.getText("adress"), (int)(colAdress +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString (lang.getText("zip"), (int)(colZip +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString (lang.getText("post"), (int)(colDistrict +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString (lang.getText("phone"), (int)(colPhone +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString (lang.getText("cvr"), (int)(colCVR +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawLine((int)(colName + autoScrol.getX()), (int)(y -
autoScrol.getY()), (int)(maxWidth + autoScrol.getX()),(int)(y +
autoScrol.getY()));
y += lineHeight;
headerPrinted = true;
}

public int print(Graphics g, PageFormat pf, int pageIndex)
{
int response = Printable.NO_SUCH_PAGE;
if(!headerPrinted)
printHeader(g,pf);
System.out.println("PageIndex:"+pageIndex);
System.out.println("Pages:"+pages);
System.out.println("Printable.NO_SUCH_PAGE:"+Printable.NO_SUCH_PAGE);
System.out.println("Printable.PAGE_EXISTS:"+Printable.PAGE_EXISTS);

if (pageIndex >= pages)
{
response = Printable.NO_SUCH_PAGE;
}
else
{
for(int i = 0; i <= lines_on_page && sheet.hasNext(); i++)
{
firm = (Firm)sheet.next();
System.out.println(firm.getName());
g2d.drawString(firm.getName(), (int)(colName +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString(firm.getAdress(), (int)(colAdress +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString(firm.getZipcode(), (int)(colZip +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString(firm.getDistrict(), (int)(colDistrict +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString(firm.getPhone(), (int)(colPhone +
autoScrol.getX()), (int)(y + autoScrol.getY()));
g2d.drawString(firm.getCVRnumber(), (int)(colCVR +
autoScrol.getX()), (int)(y + autoScrol.getY()));
y += lineHeight;
}
response = Printable.PAGE_EXISTS;
}
System.out.println(Printable.PAGE_EXISTS);
return response;
}
}
********************************/



 
 
Søg
Reklame
Statistik
Spørgsmål : 177453
Tips : 31962
Nyheder : 719565
Indlæg : 6408143
Brugere : 218879

Månedens bedste
Årets bedste
Sidste års bedste