Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
  1. #21
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: Printing formatted strings to laser printer

    You never set the font on the Graphics object, you just create a Font object and do nothing with it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: Printing formatted strings to laser printer

    Thanks for your answer but it is over my head as an absolute beginner! Could you please indicate where and how I should set the font?

  3. #23
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Printing formatted strings to laser printer

    Quote Originally Posted by alan2 View Post
    Thanks for your answer but it is over my head as an absolute beginner! Could you please indicate where and how I should set the font?
    Tolls gave you the link to the answer already in reply #19 ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #24
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: Printing formatted strings to laser printer

    Hi Jos

    That is far too cryptic for me. Is there another forum you could suggest where there is not such a fixation with not spoonfeeding the questioner with the actual code? I do need spoonfeeding with just this one problem of setting the font, ie where and what to actually say.

  5. #25
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Printing formatted strings to laser printer

    Did you click (and read!) the supplied link? b.t.w. what is cryptic about it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #26
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: Printing formatted strings to laser printer

    Yes but like all the Java documentation it is too abstract for the real beginner.

    I can't see the actual printed syntax nor where to place the lines of code. I'm starting to think that no-one here has actually successfully changed the font on a laser printer via Java code, and that is why I cannot get a direct answer!

  7. #27
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default Re: Printing formatted strings to laser printer

    If you have a Font f you want to use and you have a Graphics object g, what is too abstract about g.setFont(f)?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #28
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: Printing formatted strings to laser printer

    It's probably a matter of how I have tried to implement this. This is part of my code...


    Java Code:
    Graphics2D g2d= (Graphics2D)g;
                            g2d.translate(pf.getImageableX(), pf.getImageableY()); 
                            g.setFont(Font.MONOSPACED, 14);
    The g.setFont line gives me an error and I can't fathom out why

  9. #29
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: Printing formatted strings to laser printer

    Got it at last!

    Font af = new Font("Monospaced", Font.BOLD, 18);
    g.setFont(af);

    As you can see, my previous attempt did not use the new...

    Cheers Jos!
    Last edited by alan2; 04-04-2013 at 02:03 AM.

  10. #30
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: Printing formatted strings to laser printer

    If you plan on translating your VB stuff into Java you are really going to have to learn Java first.
    Calling methods on an object (and reading the API) are Java 101.

    Here's the Java tutorial from Oracle.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #31
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: Printing formatted strings to laser printer

    You are of course right, but everyone learns in their own way. I found it helpful in vb6 (starting from absolute scratch) to have a real world product in mind and to try to build it while filling in basic concepts. Sure, I had to unlearn one or two things on the way, but on the whole it worked. I will combine a structured ground up learning program with the same method for Java.

  12. #32
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: Printing formatted strings to laser printer

    Not that that isn't a useful learning technique, for something like Java you probably need to lower your sights a bit.
    You are not just learning Java here.
    You are learning Java...and Swing....and graphics...and printing.

    I would suggest trying to get a basic non-GUI version running, without printing (just output to a file).
    Then add in Swing.
    At least that way you have a chance to learn the basics.

    This is not (as you've seen) VB. It is not built as a GUI language. It has a GUI framework (actually several), but that's all it is, a framework on top of the language. VB is the GUI.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Page 2 of 2 FirstFirst 12

Similar Threads

  1. printing to a laser printer
    By alan2 in forum New To Java
    Replies: 14
    Last Post: 03-20-2013, 07:47 AM
  2. printing to printer
    By ak88 in forum Advanced Java
    Replies: 3
    Last Post: 01-13-2013, 03:32 PM
  3. Printer loop the same printing
    By kiki2009 in forum Advanced Java
    Replies: 2
    Last Post: 04-29-2011, 05:43 PM
  4. Printing in a printer
    By UJJAL DHAR in forum Advanced Java
    Replies: 5
    Last Post: 01-29-2011, 12:03 PM
  5. Printing Text using printer
    By UJJAL DHAR in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •