You are not logged in.

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

1

Saturday, December 10th 2011, 1:13am

JBGrid - .Parent.print()

Hey there,
I am using the JBGrid to print data from a database.
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:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Option Explicit

Public Sub Form_Load()
   JBGrid1.HeaderHeight = 0  
   JBGrid1.HeaderVisible = False 
   JBGrid1.Parent.setShowGrid(False)
   JBGrid1.BorderStyle= fmBorderStyleNone
   JBGrid1.BorderColor=vbWhite
   JBGrid1.GridColor=vbWhite
   JBGrid1.Parent.disable
   JBGrid1.Cols = 3
   Dim x As Integer
   For x = 0 To 99
      JBGrid1.DataMatrix(x,1)= "row " & x & " / col 1"
   Next
   JBGrid1.Rows = x

   JBGrid1.Parent.setBorder(BorderFactory.createEmptyBorder())  
End Sub

Public Sub Command1_Click()
   JBGrid1.Parent.print()
End Sub


You can preview by choosing -> Fax in the printeroption window and find your way to -> FaxPreview

Anyone any thoughts on this one?
Or maybe some other way to print the content of a JBGrid (with pictures) over a couple of pages?

Dani

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

2

Saturday, December 10th 2011, 1:21am

I found this post:

http://www.coderanch.com/t/346937/GUI/ja…-without-border

but I am not sure what to do with it!?

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

4

Sunday, February 3rd 2013, 6:32pm

Hey there,

I have been trying to get this to work but I can not figure out how to override Method getPrintable() of JTable and reference to the external
TablePrintable.class (Java) that will not draw a border around the table.

I created a class in Jabaco with JTable as Superclass to override Method getPrintable() of JTable which is called by its print() Methods.


Jabaco Source

1
2
3
4
5
6
7
8
9
10
'-> Import "...\overrideTablePrintable\TablePrintable.class"
Import #TablePrintable

Public Function getPrintable(ByVal myGrid As JTable, _
                              ByVal printMode As javax#swing#JTable$PrintMode, _
                              ByVal headerFormat As MessageFormat, _
                              ByVal footerFormat As MessageFormat) As Printable

   getPrintable = New #TablePrintable(JBGrid1, printMode, headerFormat, footerFormat)
End Function

But I am not sure how to reference this class to the JBGrid1 in Form1 so that it will use the custom TablePrintable.class as a substitude.

Does anyone know how to do this?

A Java equivalent for what I am looking for would be:


Source code

1
2
3
4
5
6
7
8
9
//Declare New class TablePrintable.class (MyPrintable) For the Return Type
//Override the getPrintable-Method In your JTable.

    dataTable = New javax.swing.JTable(){
        @Override
        Public Printable getPrintable( PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat ) {
            Return New MyPrintable( this, printMode, headerFormat, footerFormat );
        }
    };

I found that on the web

I would also like to know:
am I realy importing "...\overrideTablePrintable\TablePrintable.class" with

Source code

1
Import TablePrintable


or could that also reference

Source code

1
javax#swing#TablePrintable


I know how to set classpath references -> F1 -> checkBoxes -> and so on, but I would like to know if I am setting the path to external classes in my code at designtime correctly?
And if not how would I do that in code?


Dani

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Tuesday, February 12th 2013, 10:03am

Hey there,

in case anyone is interested...
This is how I got the above to work.
Create a new Class Module:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Option Explicit

'### Base = SuperClass = e.g. JTable
'### Me = this = this class

'### Jabaco Properties Pane (on your right) -> set SuperClass -> javax/swing/JTable

'### Import #TablePrintable 
'### hit F1 and import (Add Folder) -> Path of modified TablePrintable.class

'### NOT: javax#swing#TablePrintable

'### it might be a BUG in Jabaco, every time you open the Project 
'### you have to Import that class again; it does not stay in the Imports Window!

'### in Form1 Dim jt As New #DrvdJTable() -> name of this class
'### construct and add jt in Form1

Public Sub class_initialize()
   Debug.Print "init..."
End Sub

Public Function getPrintable(ByVal printMode As javax#swing#JTable$PrintMode, _
                              ByVal headerFormat As MessageFormat, _
                              ByVal footerFormat As MessageFormat) As #Printable
   Debug.Print "override getPrintable..."
   '### delegate to substitute class
   getPrintable = New #TablePrintable(Base, printMode, headerFormat, footerFormat)
End Function


I know you are missing the modified TablePrintable.class here. The code is copyrighted and I do not know if I can just post it here.
Anyways since this is for private testing only...
I found the original code here:

http://kickjava.com/src/javax/swing/TablePrintable.java.htm

Find and uncomment this line of code:

Source code

1
g2d.drawRect(0, 0, clip.width, hclip.height + clip.height);


Compile the source to TablePrintable.class and drop that file to you project path.


Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

6

Tuesday, February 12th 2013, 10:49am

I know you are missing the modified TablePrintable.class here. The code is copyrighted and I do not know if I can just post it here.
Anyways since this is for private testing only...
I found the original code here:

http://kickjava.com/src/javax/swing/TablePrintable.java.htm

It seems to be the old non-opensource version.

Since some years Java is OpenSource as OpenJDK:
http://openjdk.java.net/

Here the OpenJDK7 source:
http://hg.openjdk.java.net/jdk7/jdk7/jdk…ePrintable.java
I know, it isn't easy to find the way through the mercurial directories (dont know why so many people prefer mercurial and git over svn and cvs).

The License of OpenJDK:
GPL + GNU Classpath exception.

GPL means, that the complete program have to be under an GPL-compatible license, too.
But the GNU Classpath exception says, that the GPL stands only for the one *.java file. It can be linked (dynamical and static!) against any other file of any other license. The LGPL - for example - only allows dynamical linking against LGPL-incompatible licensed files. So GPL + GNU Classpath exception allows more then the LGPL.

Here the LICENSE file:
http://hg.openjdk.java.net/jdk7/jdk7/jdk…a2434b1/LICENSE

Greatings
theuserbl

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

7

Tuesday, February 12th 2013, 11:00am

It seems to be the old non-opensource version.

Btw: With "old" I mean only that the license is the old one. It can be possible, that a file is over ten years unchanged, only the license changed. Then the non-opensource file is the old one and the opensource one is the new one.

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

8

Tuesday, February 12th 2013, 1:26pm

Hey there theuserbl,

thanks for that link.
There has been a little change to the code too:

http://hg.openjdk.java.net/jdk7/jdk7/jdk…ePrintable.java

but since I do not have javac I can not compile the new source.
Do you have any link to download a sole java compiler without all the overhead of a sun JDK?
At least it seems like it is a lot of overhead!

I still have a question that I mentioned before in this thread

Quoted

I would also like to know:
am I realy importing "...\overrideTablePrintable\TablePrintable.class" with

Source code

1
Import TablePrintable


or could that also reference

Source code

1
javax#swing#TablePrintable


I know how to set classpath references -> F1 -> checkBoxes -> and so on, but I would like to know if I am setting the path to external classes in my code at designtime correctly?
And if not how would I do that in code?


OK, well I managed to get it right, but how can I do all the referencing in code?

How do I Set the SuperClass for a SubClass in code?
How do I Set a reference for my external TablePrintable.class file in code?

Source code

1
Import TablePrintable


works, but I see a chance where it gets mixed up with

Source code

1
javax#swing#TablePrintable


or could that not happen?


Dani


PS: did you see my current bugreport? Thats why I am wondering if I coul not set the reference in my code!

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

9

Wednesday, February 13th 2013, 2:29am

Do you have any link to download a sole java compiler without all the overhead of a sun JDK?


Which JRE-version do you have?


I have now temporary uploaded a self-compiled Java 7 javac;
http://jbaindi.googlecode.com/files/javac.jar
Compile with

Source code

1
java -jar javac.jar Program.java


If you have Java 6, then I will compile it later for you, if you want it.
Until this time, you can use the uploaded tools.jar from Roberts unimozer side:
unimozer.fisch.lu/webstart/tools.jar
Compile with

Quoted

java -cp tools.jar com.sun.tools.javac.Main Program.java


Using a Java 7 javac on an Java 6 runtime, is not possible. Because programs which are compiled with and for an heigher Java-version are not running on an lower Java runtime.
And using Java 6 javac on an Java 7 runtime, is possibvle, but outputs after every compiling a lot of warnings.


Quoted

I would also like to know:
am I realy importing "...\overrideTablePrintable\TablePrintable.class" with

Source code

1
Import TablePrintable


or could that also reference

Source code

1
javax#swing#TablePrintable

It is everytime better to use the full path. then you are on the safe side. More than ever, if the class name existing more then one time.

There are already existing some classes, which name existing more then one time. Fore example Frame:
VB#Frame
java#awt#Frame
com#sun#xml#internal#ws#org#objectweb#asm#Frame


Quoted

OK, well I managed to get it right, but how can I do all the referencing in code?

Don't know, what you mean.

Quoted

How do I Set the SuperClass for a SubClass in code?

In Java? Width "extends".
In Jabaco? Create a new "Class Module" and set the SuperClass in the Properties-area on the right bottom of the Jabaco-window.


Greatings
theuserbl

This post has been edited 2 times, last edit by "theuserbl" (Feb 13th 2013, 2:54am)


Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

10

Wednesday, February 13th 2013, 10:33am

Hi,

I have Java 1.7.0_03, so thanks a lot. Makes me a bit more independent ;)

Quoted

It is everytime better to use the full path. then you are on the safe side. More than ever, if the class name existing more then one time.
...
Don't know, what you mean.


That is exactly what I meant... I don't know how to use the full path to my TablePrintable.class file in my programs' directory.
I thought this would refer to my Projects Path, how else would I refer to the full path?

Jabaco Source

1
Import #TablePrintable

But you answered to my Bugreport to use a .jar file instead, so I will do that. Very good to know!!



Quoted

Quoted

How do I Set the SuperClass for a SubClass in code?


In Java? Width "extends".
In Jabaco? Create a new "Class Module" and set the SuperClass in the Properties-area on the right bottom of the Jabaco-window.


Of course I know that ... but is there a way to set the SuperClass for this "Class Module" in my code?
Like in Java with "extends" If for example I would write that class in a texteditor.
(I am not talking about the xml tag here!!)


Thanks again ...


Dani

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

11

Wednesday, February 13th 2013, 2:23pm

Hmm,

I have just tested putting the TablePrintable.class file in a .jar file and importing that to my Project.
The problem is that Jabaco also automatically imports:

Jabaco Source

1
javax#swing#TablePrintable


so I have both referenced to my Project now and

Jabaco Source

1
2
3
4
5
6
7
Public Function getPrintable(ByVal printMode As javax#swing#JTable$PrintMode, _
                              ByVal headerFormat As MessageFormat, _
                              ByVal footerFormat As MessageFormat) As java#awt#print#Printable
   Debug.Print "override getPrintable..."
   '### delegate to substitute class
   getPrintable = New #TablePrintable(Base, printMode, headerFormat, footerFormat)
End Function


throws an 'IllegalAccessError for javax.swing.TablePrintable' !
As soon as both TablePrintable.classes are imported the above overriding does not work anymore.
TablePrintable.class in my .jar file is being ignored.

Again my question:
Is there a way be more specific abaout the custom path of my New #TablePrintable


Dani



EDIT:

Well, the new Version of TablePrintable had referenced:

Source code

1
2
3
4
5
6
7
 package javax.swing;
 
 import javax.swing.table.*;
 import java.awt.*;
 import java.awt.print.*;
 import java.awt.geom.*;
 import java.text.MessageFormat;


the old version:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.text.MessageFormat;

import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;


I exchanged the one's of the new version and now it works with the .jar/.zip import.

BUT: imagine you need both versions of a class in the same Project!?
Since the naming conventions of Java require you to use the same name in the SubClass that would not work with Jabaco!


Dani

This post has been edited 1 times, last edit by "Dani" (Feb 13th 2013, 4:11pm)


theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

12

Friday, February 15th 2013, 12:15am

Can you please repost the part, which you want to change on TablePrintable.

From which code to which code you want to change it.
Only the part you want to change. Not the complete one.

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

13

Friday, February 15th 2013, 8:42am

Hey there theuserbl,

as I wrote above in this thread, this is all I changed in the class

Quoted

g2d.drawRect(0, 0, clip.width, hclip.height + clip.height);


BUT:
I had to change all the Imports because otherwise Jabaco would throw errors on TablePrintable because it would only refer to

Quoted

javax#swing#TablePrintable


and not to my own

Quoted

#TablePrintable


...so if you have a Project with bot classes Jabaco throws Errors!

So I had to be more specific with the Import section of the new version of TablePrintable

Quoted

I exchanged the one's of the new version and now it works with the .jar/.zip import.


AND: I had to make sure that there is no reference to


Quoted

javax#swing#TablePrintable


AGAIN: both classes in one Project did not work!

I don't need help on this one, just wanted to know if there is a way to have them both imported!



Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

14

Friday, February 15th 2013, 11:47am

as I wrote above in this thread, this is all I changed in the class

Quoted

g2d.drawRect(0, 0, clip.width, hclip.height + clip.height);


The "print"-method is "public".

So you can create a new file for example called "NewTablePrintable.java"

And lets say we want to see it in the VBA-directory, then the code of this file would look like

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package VBA;

import javax.swing.table.*;
import javax.swing.*;
import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;
import java.text.MessageFormat;

class NewTablePrintable extends TablePrintable {

 private JTable table;
 private JTableHeader header;
 private TableColumnModel colModel;
 private int totalColWidth;
 private JTable.PrintMode printMode;
 private MessageFormat headerFormat;
 private MessageFormat footerFormat;
 private int last = -1;
 private int row = 0;
 private int col = 0;
 private final Rectangle clip = new Rectangle(0, 0, 0, 0);
 private final Rectangle hclip = new Rectangle(0, 0, 0, 0);
 private final Rectangle tempRect = new Rectangle(0, 0, 0, 0);
 private static final int H_F_SPACE = 8;
 private static final float HEADER_FONT_SIZE = 18.0f;
 private static final float FOOTER_FONT_SIZE = 12.0f;
 private Font headerFont;
 private Font footerFont;

  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
    throws PrinterException {


    // for easy access to these values
       final int imgWidth = (int)pageFormat.getImageableWidth();
       final int imgHeight = (int)pageFormat.getImageableHeight();
       if (imgWidth <= 0) {
         throw new PrinterException("Width of printable area is too small.");
       }

      // to pass the page number when formatting the header and footer text
    Object[] pageNumber = new Object[]{Integer.valueOf(pageIndex + 1)};

   // fetch the formatted header text, if any
    String headerText = null;
    if (headerFormat != null) {
    headerText = headerFormat.format(pageNumber);
    }


  // *** Input the complete modified print-method here **

  }
}


Fill the method.


This is the way, how it nomally works.

And then change later in JBGrid TablePrintable to NewTablePriontable.

Greatings
theuserbl

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

15

Friday, February 15th 2013, 12:03pm

Possibly the little OOPJava.pdf file helps you to understand one part of Java.

Thats something I have had in the the most problems with, to understand it.
On January 2010, after I understood it, I have created this pdf-file (it is in german).

Greatings
theuserbl

Edit: Have only little changed it
theuserbl has attached the following file:
  • OOPJava.pdf (42.53 kB - 565 times downloaded - latest: Mar 29th 2024, 1:51am)

This post has been edited 1 times, last edit by "theuserbl" (Feb 15th 2013, 12:33pm)


Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

16

Friday, February 15th 2013, 12:40pm

Hey there theuserbl,

Quoted

... class NewTablePrintable extends TablePrintable ...


OK so I would have to write a Java SubClass to avoid the doublicate names of the Imported class.files in Jabaco!

Quoted

OOPJava.pdf


sehr schöner Aufsatz...
That is pretty much what the whole Jabaco Framework is about!

Thanks for helping,


Dani

Rate this thread
WoltLab Burning Board