Double-Sided

F

freesoft_2000

Hi everyone,

I am currently trying to print a swing component a JTable to
be exact but the thing is that i want my user to be able to print even,
odd or all the pages. The thing is i am using the swing print dialog and
not the windows native one.

When i write i use the printer job the java printing system will call the
page indexes as follows:

Code:
print(graphics, pageFormat, 0)
print(graphics, pageFormat, 1)
print(graphics, pageFormat, 2)

As you can see from above all the page numbers are called sequentially
until NO_SUCH_PAGE is returned.

Well what i am trying to say is that is possible to make the java printing
system only call odd page indexes
something like this

Code:
print(graphics, pageFormat, 0)
print(graphics, pageFormat, 2)
print(graphics, pageFormat, 4)

I know that it is also possible to print double side page by adding
attributes to the PrintRequestAttributeSet class by using the below line

Code:
add(Sides.DUPLEX)

This is not a very good option as it requires an expensive printer for
this and not many users have this type of expensive printer.

I hope i haven't confused you guys and maybe someone can explain or guide
me to a way to printing even and odd pages.

Please note that the JTable is three pages long

Thank You

Yours Sincerely

Richard West
 
M

Mario Winterer

Hi!

I think you cannot tell the printing system to just call odd or even pages.
But you can do that for yourself inside your print-method! Just do a conversion of the sequence 0,1,2,... into the sequence you want
(e.g. 0,2,4,... or 1,3,5...). The rest of your print method should then display the correct part of your table:

Code:
public int print(Graphics graphics, PageFormat format, int pageIndex) {
if (/*even pages?*/){
pageIndex = pageIndex * 2 + 1; // 1,3,5,...
} else if (/* odd pages? */) {
pageIndex = pageIndex * 2; // 0,2,4,...
}
....
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top