Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javax.swing.JTable.print()

Reply
Thread Tools

javax.swing.JTable.print()

 
 
beowolf
Guest
Posts: n/a
 
      05-06-2010
Hi all,
this code works as expected when it's inline in the program:
(jTAfd is "public static javax.swing.JTable jTAfd;"):

try {
jTAfd.print(JTable.PrintMode.FIT_WIDTH, null, null);
} catch (Exception pe) {
System.err.println("*** Error printing: " + pe.getMessage());
}

when I try to make it as a routine (whit the table to be printed
passed as parameter):

Component componente = null;
componente = jTAfd;
myPrint(componente);
.....
void myPrint(Component c){
try {
c.print(JTable.PrintMode.FIT_WIDTH, null, null);
} catch (Exception pe) {
System.err.println("*** Error printing: " + pe.getMessage());
}
}

it does not compile:
.... print(java.awt.Graphics) in java.awt.Component cannot be applied
to
(javax.swing.JTable.PrintMode,<nulltype>,<nulltype >)
c.print(JTable.PrintMode.FIT_WIDTH, null, null);

why does javac picks up print(Graphics) instead of
javax.swing.JTable.print(); ?
I've tried almost all reasonable includes, can anyone help me ?
Thank you !
 
Reply With Quote
 
 
 
 
Java coder
Guest
Posts: n/a
 
      05-06-2010
beowolf a écrit :

> void myPrint(Component c){
> try {
> c.print(JTable.PrintMode.FIT_WIDTH, null, null);
> } catch (Exception pe) {
> System.err.println("*** Error printing: " + pe.getMessage());
> }
> }
>
> it does not compile:
> ... print(java.awt.Graphics) in java.awt.Component cannot be applied
> to
> (javax.swing.JTable.PrintMode,<nulltype>,<nulltype >)
> c.print(JTable.PrintMode.FIT_WIDTH, null, null);
>
> why does javac picks up print(Graphics) instead of
> javax.swing.JTable.print(); ?
> I've tried almost all reasonable includes, can anyone help me ?


You must be beginner... What's the type of c in your method ? Does this
type have the method print() with 3 parameters ?
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      05-06-2010
On 05/06/2010 02:55 AM, beowolf wrote:
> this code works as expected when it's inline in the program:
> (jTAfd is "public static javax.swing.JTable jTAfd;"):
>
> try {
> jTAfd.print(JTable.PrintMode.FIT_WIDTH, null, null);


Here the variable is declared as 'JTable', presumably. You don't show the
code so we have to hope you declared it correctly.

> } catch (Exception pe) {
> System.err.println("*** Error printing: " + pe.getMessage());
> }
>
> when I try to make it as a routine (whit the table to be printed
> passed as parameter):
>
> Component componente = null;
> componente = jTAfd;
> myPrint(componente);
> ....
> void myPrint(Component c){


Here, 'c' is declared as 'Component', and that type does not have the method
overload you try to use.

> try {
> c.print(JTable.PrintMode.FIT_WIDTH, null, null);
> } catch (Exception pe) {
> System.err.println("*** Error printing: " + pe.getMessage());
> }
> }
>
> it does not compile:
> ... print(java.awt.Graphics) in java.awt.Component cannot be applied
> to
> (javax.swing.JTable.PrintMode,<nulltype>,<nulltype >)
> c.print(JTable.PrintMode.FIT_WIDTH, null, null);
>
> why does javac picks up print(Graphics) instead of
> javax.swing.JTable.print(); ?


Because 'c' is a 'Component' variable, not 'JTable'.

> I've tried almost all reasonable includes, can anyone help me ?


What do you mean by "includes"?

The compiler has no way to know the run-time type of 'c'; it has to work only
with the compile-time type.

You also should not mix AWT components and Swing components.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments