Re: javax.swing.JTable.print()
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