javax.swing.JTable.print()

B

beowolf

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 !
 
J

Java coder

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 ?
 
L

Lew

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.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top