You are not logged in.

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

1

Monday, January 14th 2013, 5:19pm

send my textfields and JBGrid to printer

Hi again.
I have some textfields and a JBGrid with some rows(results after a search).
I also have a button "print".
How can i send my data to the printer.

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

3

Tuesday, January 15th 2013, 11:43am

Thank you very much Dani!
I wish i knew your language it could help me more :( .
I will have a look at the links!

Thank you very much again!

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

4

Tuesday, January 15th 2013, 1:56pm

Dani because i did not have my printer in my laptop now i used
microsoft xps document writer (as a test preview)

JBGrid1.parent.print work perfect but i wonder is there a way to have my

textfield1.parent.print AND textfield2.parent.print (IN ONE ROW)
JBGrid1.parent.print

ALL IN ONE PRINT!


for example i need something like this
from_date:21-05-2013 to_date:26-05-2013
JBGrid1 RESULTS

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Tuesday, January 15th 2013, 5:52pm

Hey there,

it seems like there is a way to customize printing a JTable:

see: http://docs.oracle.com/javase/tutorial/u…printtable.html

Jabaco Source

1
2
3
4
Dim Success As Boolean     
   Dim headerFormat As MessageFormat = New MessageFormat("Page {0}")
   Dim footerFormat As MessageFormat = New MessageFormat("- {0} -")
   Success = JBGrid1.Parent.print(JTable.PrintMode.FIT_WIDTH , headerFormat, footerFormat)


However, I dont know how to expose

Quoted

JTable.PrintMode


I don't have the time to get into it right now...sorry!
So, if you get it to work, let me know... ?(


Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

6

Wednesday, January 16th 2013, 4:19pm

Dani i am trying different ways to have the footer and header BUT until now i did not succeed it.
I do not know what i am doing wrong but i am still having nothing as header/footer.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

7

Wednesday, January 16th 2013, 7:12pm

Hey there,

I am afraid I can not help you. As I said, I don't get a handle on JTable.PrintMode myself!

You could populate a second hidden Table (visible=False), write your HeaderMsg to the first row and only print that table!
(Maybe use it as your visible table if that Msg does not disturb you!?)

Not very satisfying but does the job for now.

Maybe someone with a bit more Java knowledge can give some advice here?


Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

8

Friday, January 18th 2013, 1:08pm

Hi Dani you helped me a lot!

Now i am printing separately

JBGrid1.Parent.print
and then
JBGrid2.Parent.print

Do you now a way to print JBGrid1 and JBGrid2 in one page - print?

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

9

Friday, January 18th 2013, 5:21pm

Hey there,

I am not sure what exactly you did?
Are you using a second hidden JBGrid now?
If you do:
- set JBGrid1.HeaderVisible = False
- populate and format the first row, center cell with your custom title
- leave the second row empty
- populate the 3rd row with your header titles, format accordingly with html syntax
- populate the rest of the grid with the content of your visible grid

just an example, I don't know what you are after...

I did not have a use for printing yet; did you look into using a printer object?
It should not be too hard to write your tables content to a file and send that file to the printer.
You will be much more flexible with that!
There is a little bit about printing in the forum.

http://www.jabaco.org/board/p2331-drucken-wie.html#post2331
http://www.jabaco.org/board/p1042-printing-rtf.html#post1042

here you can find a class that produces html output for printing:
http://www.jabaco.org/board/p2528-creati…o.html#post2528


Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

10

Monday, January 21st 2013, 3:55pm

Dani i was trying to do something like this

Jabaco Source

1
2
3
4
5
Public Sub Printtxt
Dim File As vbFileHandler = Open("TempFile.txt") 
Write(File,RichTextBox1.Text) 
Dim D As Desktop = Desktop.getDesktop 
D.print(New file("TempFile.txt"))End Sub


but line

Jabaco Source

1
Dim D As Desktop = Desktop.getDesktop


occurs compile error

Have you got any idea why i have got this error?

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

11

Monday, January 21st 2013, 8:14pm

Hey there,

why don't you just use the code by A1880 I provided a link to!?

Drucken, wie ?

it works fine for me...

Now here is a little update on printing a JBGrid, JTable with custom parameters, print dialog, header, footer, pagenumber and so on:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Public Sub Command1_Click()
   Dim Success As Boolean

   Dim strHeader As MessageFormat = New MessageFormat("Page {0}")
   Dim strFooter As MessageFormat = New MessageFormat("- {0} -")
   
'   table.print(JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat, 
'               Boolean showPrintDialog, PrintRequestAttributeSet attr, Boolean interactive, PrintService service)
'   JTable$PrintMode.NORMAL
   Success = JBGrid1.Parent.print(JTable$PrintMode.FIT_WIDTH , strHeader, strFooter, True, Null, False, Null)
End Sub

:D

Dani

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

12

Monday, January 21st 2013, 8:45pm

Hey there,

I pointed out in another thread
http://www.jabaco.org/board/p3071-jbgrid…t.html#post3071
that when printing a Jtable that...

Quoted

...
Unfortunately there is a border in the printed version surounding the grid that I can not get rid of!
I tried all sorts of things to make that border disappear:
...


I now know that this is hardcoded in the JavaClass TablePrintable.java
I have changed that class so it will not draw that box!! :whistling:
However I don't have a java compiler on my system and don't want to install a whole package just to compile this one class!!
If someone is willing to do that here is the source (look for the tag 'Dani' and you will find what I outcommented in the code)

MyPrintable.java

Once we have that class compiled we would have to override SuperClass TablePrintable of JTable and redirect to MyPrintable!
I am not quite sure how to do the 'redirect ' part though!?

Anyone interested in helping out here...?


Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

13

Wednesday, January 23rd 2013, 11:18am

Hi Dani i am using microsoft xps document writer (as a test preview) because i do not have a printer now.
There i can not see header or footer.
Can you?
Is there a possibility to see them ONLY when i print it?
Dim Success As Boolean Dim strHeader As MessageFormat = New MessageFormat("Page {0}") Dim strFooter As MessageFormat = New MessageFormat("- {0} -") ' table.print(JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat, ' Boolean showPrintDialog, PrintRequestAttributeSet attr, Boolean interactive, PrintService service) ' JTable$PrintMode.NORMAL Success = JBGrid1.Parent.print(JTable$PrintMode.FIT_WIDTH , strHeader, strFooter, True, Null, False, Null)

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

14

Wednesday, January 23rd 2013, 6:25pm

Hey there,

it works now

Jabaco Source

1
2
3
4
5
6
7
8
Public Sub Command1_Click()
   Dim Success As Boolean

   Dim strHeader As MessageFormat = New MessageFormat("Page {0}")
   Dim strFooter As MessageFormat = New MessageFormat("- {0} -")

   Success = JBGrid1.Parent.print(JTable$PrintMode.FIT_WIDTH , strHeader, strFooter, True, Null, False, Null)
End Sub


This little symbol $ makes all the difference!!

I am using edocprint to redirect printer output to .pdf files and header and footer show fine.

Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

15

Thursday, January 24th 2013, 12:14pm

Dani edocprint worked perfect to me too.

Do you now ...
1. if i can change the font size of header?
2. can i preset "landscape"
3. can i preset "margins" (top,left,right.left) instead of 25,4 TO 4?

Thank you for your help and your time!

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

16

Thursday, January 24th 2013, 1:06pm

Hey there,

it is all possible!!

Look for these in the internet

Quoted

JTable printing HashPrintRequestAttributeSet
customized printing JTable



just to give you an idea

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
Import javax.print.attribute.HashPrintRequestAttributeSet
Import javax.print.attribute.standard.OrientationRequested

Public Sub Command1_Click()
   Dim Success As Boolean

   Dim strHeader As MessageFormat = New MessageFormat("Page {0}")
   Dim strFooter As MessageFormat = New MessageFormat("- {0} -")
   Dim Mode As JTable$PrintMode = FIT_WIDTH
   Dim printRequestAttributeSet As javax#print#attribute#HashPrintRequestAttributeSet = New HashPrintRequestAttributeSet()
   printRequestAttributeSet.add(OrientationRequested.LANDSCAPE)   
   Success = JBGrid1.Parent.print(Mode , strHeader, strFooter, True, printRequestAttributeSet, False, Null)
End Sub


BUT: be very carefull with what you are 'importing' you are adding a lot of weight to your project!!


Dani

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

17

Thursday, January 24th 2013, 1:21pm

Unfortunately when i make imports i have many compile errors but i will make some more effords

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

18

Saturday, January 26th 2013, 1:16pm

Something strange happening.
When i am trying to run my project i have this error...

java.lang.Exception: CallByName 'FIT_WIDTH' failed!

BUT when i delete the code and write again it works!
When i close my pc and next day open to work i happens again.

Have you got any idea?

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

19

Saturday, January 26th 2013, 1:52pm

java.lang.Exception: CallByName 'FIT_WIDTH' failed!

BUT when i delete the code and write again it works!
When i close my pc and next day open to work i happens again.

Have you got any idea?


Try to write the complete part:

Jabaco Source

1
Dim Mode As javax#swing#JTable$PrintMode = javax#swing#JTable$PrintMode.FIT_WIDTH


Jabaco IDE and Jabaco Compiler are working together. When you write the code the IDE doing more.

Greatings
theuserbl

fomaxrge

Trainee

  • "fomaxrge" started this thread

Posts: 88

Date of registration: Aug 14th 2012

  • Send private message

20

Monday, January 28th 2013, 11:47am

I will test it but as i see it Works!

Thank you! :thumbup:

Similar threads

Rate this thread
WoltLab Burning Board