javax.swing.JTable.print()

Discussion in 'Java' started by beowolf, May 6, 2010.

  1. beowolf

    beowolf Guest

    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 !
    beowolf, May 6, 2010
    #1
    1. Advertising

  2. beowolf

    Java coder Guest

    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 ?
    Java coder, May 6, 2010
    #2
    1. Advertising

  3. beowolf

    Lew Guest

    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
    Lew, May 6, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arun Kumar Srinivasan

    Using javax.print classes to print text/file

    Arun Kumar Srinivasan, Jan 13, 2004, in forum: Java
    Replies:
    5
    Views:
    6,149
    Gregory A. Swarthout
    Jan 14, 2004
  2. hiwa
    Replies:
    1
    Views:
    1,132
    Thomas Weidenfeller
    Mar 9, 2005
  3. lizard
    Replies:
    0
    Views:
    1,765
    lizard
    Jan 30, 2006
  4. S.T
    Replies:
    2
    Views:
    579
  5. Pascal
    Replies:
    0
    Views:
    417
    Pascal
    Oct 24, 2008
Loading...

Share This Page