Results 1 to 2 of 2
  1. #1
    scana is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default Printing JFrame + it`s content

    maybe some of you guys will be able to help me.

    This is a little part of my crossword generator.

    I`m not able to get my whole JFrame to be printed (using some PDF printer). All I can get is blank page with grey rectangle (like it`s printing only a background of this window).

    I`ve implemented this to able to print stuff.
    Java Printing - Java - Source Code |

    Few of my classes

    Main window - (the one that I`m trying to print)
    Java Code:
    public class Krzyzowka extends JFrame{
           private Crossword cw;
    	public Krzyzowka(Crossword x) { = x;
    			Grafa d = new Grafa(cw);
    			d.setSize(80, 80);
    JFrame content - I draw the whole crossword here - well, it would be even better if some1 could help me with printing only this thing.
    I`ve cut out some of the code, cause it`s here only for that u could get an idea how I`m drawing this.
    Java Code:
    public class Grafa extends Panel{
    	private Crossword cw;
    	public Grafa(Crossword cw) { = cw;
    	public void paint(Graphics arg0) {
    		Board board = cw.getBoard();
    		Graphics g = getGraphics();
    		int i=0;
    		for (int j = 0; j < board.getHeight(); ++j){
    		 for (i = 0; i < board.getWidth(); ++i) 
    				if (board.getCell(i, j).getContent().length() > 0) {
    					if(!board.getCell(i, j).getContent().contentEquals("\0")){
    						g.drawRect(j * 40 - 120, i * 40 + 81 , 40, 40);
    						g.drawRect(j * 40 -118, i * 40 + 83, 36, 36);
    And finally, I press the button, and window with my crossword is now visible (it works correctly), and Printing Dialog is appearing.

    Java Code:
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
                    dp1 = new Krzyzowka(test);
    		dp1.setSize(500, 500);
    Then I choose the printer (PDF one), and I`ll can get is that damn, grey rectangular :|

    Any idea how to print my crossword, anyone? Or someone could possible tell me, what I`m doing wrong?

    Sorry for my english, I hope that u will be able to understand what I mean and what I`m trying to do with this code. Ask any questions, I`ll try to respond as soon as possible.


  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Pittsburgh, PA
    Rep Power


    Marty Hall's tutorial on PrintUtilities emphasizes the need to turn off double buffering.
    I don't see in your code where you did that.

Similar Threads

  1. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  2. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  3. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  4. JFrame printing
    By greeshma in forum New To Java
    Replies: 4
    Last Post: 08-11-2008, 03:14 PM
  5. Replies: 0
    Last Post: 02-12-2008, 05:05 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