Printing JFrame

HI i am tryin to print the second class which is pasted below .. The printer dialog comes up but the page does not print .. it just comes out blank .. can any one please help :S
//this class is used to open the class below ..
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RunView extends JFrame implements ActionListener
private ButtonGroup cbg;
private JRadioButton radio80;
private JRadioButton radio79;
private JRadioButton radio78;
private JRadioButton radio77;
private JRadioButton radio76;
private JRadioButton radio75;
private JRadioButton radio74;
private JRadioButton radio73;
private JRadioButton radio72;
private JRadioButton radio71;
private JRadioButton radio70;
private JRadioButton radio69;
private JRadioButton radio68;
private JRadioButton radio67;
private JRadioButton radio66;
private JRadioButton radio65;
private JRadioButton radio64;
private JRadioButton radio63;
private JRadioButton radio62;
private JRadioButton radio61;
private JRadioButton radio60;
private JRadioButton radio59;
private JRadioButton radio58;
private JRadioButton radio57;
private JRadioButton radio56;
private JRadioButton radio55;
private JRadioButton radio54;
private JRadioButton radio53;
private JRadioButton radio52;
private JRadioButton radio51;
private JRadioButton radio50;
private JRadioButton radio49;
private JRadioButton radio48;
private JRadioButton radio47;
private JRadioButton radio46;
private JRadioButton radio45;
private JRadioButton radio44;
private JRadioButton radio43;
private JRadioButton radio42;
private JRadioButton radio41;
private JRadioButton radio40;
private JRadioButton radio39;
private JRadioButton radio38;
private JRadioButton radio37;
private JRadioButton radio36;
private JRadioButton radio35;
private JRadioButton radio34;
private JRadioButton radio33;
private JRadioButton radio32;
private JRadioButton radio31;
private JRadioButton radio30;
private JRadioButton radio29;
private JRadioButton radio28;
private JRadioButton radio27;
private JRadioButton radio26;
private JRadioButton radio25;
private JRadioButton radio24;
private JRadioButton radio23;
private JRadioButton radio22;
private JRadioButton radio21;
private JRadioButton radio20;
private JRadioButton radio19;
private JRadioButton radio18;
private JRadioButton radio17;
private JRadioButton radio16;
private JRadioButton radio15;
private JRadioButton radio14;
private JRadioButton radio13;
private JRadioButton radio12;
private JRadioButton radio11;
private JRadioButton radio10;
private JRadioButton radio9;
private JRadioButton radio8;
private JRadioButton radio7;
private JRadioButton radio6;
private JRadioButton radio5;
private JRadioButton radio4;
private JRadioButton radio3;
private JRadioButton radio2;
private JRadioButton radio1;
private JLabel infoLabel1;
private JLabel infoLabel2;
private JButton submitButton;
private JButton exitButton;
static String exDescription="";
static String exCode="";
public RunView() {
     super("Running Exercise List");
          try{
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          }catch(Exception e){
               //e.printStackTrace();
RunViewLayout customLayout = new RunViewLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
getContentPane().setLayout(customLayout);
cbg = new ButtonGroup();
radio80 = new JRadioButton("rg080", false);
cbg.add(radio80);
getContentPane().add(radio80);
radio80.addActionListener(this);
radio79 = new JRadioButton("rg079", false);
cbg.add(radio79);
getContentPane().add(radio79);
          radio79.addActionListener(this);
radio78 = new JRadioButton("rg078", false);
cbg.add(radio78);
getContentPane().add(radio78);
radio78.addActionListener(this);
radio77 = new JRadioButton("rg077", false);
cbg.add(radio77);
getContentPane().add(radio77);
radio77.addActionListener(this);
radio76 = new JRadioButton("rg076", false);
cbg.add(radio76);
getContentPane().add(radio76);
radio76.addActionListener(this);
radio75 = new JRadioButton("rg075", false);
cbg.add(radio75);
getContentPane().add(radio75);
radio75.addActionListener(this);
radio74 = new JRadioButton("rg074", false);
cbg.add(radio74);
getContentPane().add(radio74);
radio74.addActionListener(this);
radio73 = new JRadioButton("rg073", false);
cbg.add(radio73);
getContentPane().add(radio73);
radio73.addActionListener(this);
radio72 = new JRadioButton("rg072", false);
cbg.add(radio72);
getContentPane().add(radio72);
radio72.addActionListener(this);
radio71 = new JRadioButton("rg071", false);
cbg.add(radio71);
getContentPane().add(radio71);
radio71.addActionListener(this);
radio70 = new JRadioButton("rg070", false);
cbg.add(radio70);
getContentPane().add(radio70);
radio70.addActionListener(this);
radio69 = new JRadioButton("rg069", false);
cbg.add(radio69);
getContentPane().add(radio69);
radio69.addActionListener(this);
radio68 = new JRadioButton("rg068", false);
cbg.add(radio68);
getContentPane().add(radio68);
radio68.addActionListener(this);
radio67 = new JRadioButton("rg067", false);
cbg.add(radio67);
getContentPane().add(radio67);
radio67.addActionListener(this);
radio66 = new JRadioButton("rg066", false);
cbg.add(radio66);
getContentPane().add(radio66);
radio66.addActionListener(this);
radio65 = new JRadioButton("rg065", false);
cbg.add(radio65);
getContentPane().add(radio65);
radio65.addActionListener(this);
radio64 = new JRadioButton("rg064", false);
cbg.add(radio64);
getContentPane().add(radio64);
radio64.addActionListener(this);
radio63 = new JRadioButton("rg063", false);
cbg.add(radio63);
getContentPane().add(radio63);
radio63.addActionListener(this);
radio62 = new JRadioButton("rg062", false);
cbg.add(radio62);
getContentPane().add(radio62);
radio62.addActionListener(this);
radio61 = new JRadioButton("rg061", false);
cbg.add(radio61);
getContentPane().add(radio61);
radio61.addActionListener(this);
radio60 = new JRadioButton("rg060", false);
cbg.add(radio60);
getContentPane().add(radio60);
radio60.addActionListener(this);
radio59 = new JRadioButton("rg059", false);
cbg.add(radio59);
getContentPane().add(radio59);
radio59.addActionListener(this);
radio58 = new JRadioButton("rg058", false);
cbg.add(radio58);
getContentPane().add(radio58);
radio58.addActionListener(this);
radio57 = new JRadioButton("rg057", false);
cbg.add(radio57);
getContentPane().add(radio57);
radio57.addActionListener(this);
radio56 = new JRadioButton("rg056", false);
cbg.add(radio56);
getContentPane().add(radio56);
radio56.addActionListener(this);
radio55 = new JRadioButton("rg055", false);
cbg.add(radio55);
getContentPane().add(radio55);
radio55.addActionListener(this);
radio54 = new JRadioButton("rg054", false);
cbg.add(radio54);
getContentPane().add(radio54);
radio54.addActionListener(this);
radio53 = new JRadioButton("rg053", false);
cbg.add(radio53);
getContentPane().add(radio53);
radio53.addActionListener(this);
radio52 = new JRadioButton("rg052", false);
cbg.add(radio52);
getContentPane().add(radio52);
radio52.addActionListener(this);
radio51 = new JRadioButton("rg051", false);
cbg.add(radio51);
getContentPane().add(radio51);
radio51.addActionListener(this);
radio50 = new JRadioButton("rg050", false);
cbg.add(radio50);
getContentPane().add(radio50);
radio50.addActionListener(this);
radio49 = new JRadioButton("rg049", false);
cbg.add(radio49);
getContentPane().add(radio49);
radio49.addActionListener(this);
radio48 = new JRadioButton("rg048", false);
cbg.add(radio48);
getContentPane().add(radio48);
radio48.addActionListener(this);
radio47 = new JRadioButton("rg047", false);
cbg.add(radio47);
getContentPane().add(radio47);
radio47.addActionListener(this);
radio46 = new JRadioButton("rg046", false);
cbg.add(radio46);
getContentPane().add(radio46);
radio46.addActionListener(this);
radio45 = new JRadioButton("rg045", false);
cbg.add(radio45);
getContentPane().add(radio45);
radio45.addActionListener(this);
radio44 = new JRadioButton("rg044", false);
cbg.add(radio44);
getContentPane().add(radio44);
radio44.addActionListener(this);
radio43 = new JRadioButton("rg043", false);
cbg.add(radio43);
getContentPane().add(radio43);
radio43.addActionListener(this);
radio42 = new JRadioButton("rg042", false);
cbg.add(radio42);
getContentPane().add(radio42);
radio42.addActionListener(this);
radio41 = new JRadioButton("rg041", false);
cbg.add(radio41);
getContentPane().add(radio41);
radio41.addActionListener(this);
radio40 = new JRadioButton("rg040", false);
cbg.add(radio40);
getContentPane().add(radio40);
radio40.addActionListener(this);
radio39 = new JRadioButton("rg039", false);
cbg.add(radio39);
getContentPane().add(radio39);
radio39.addActionListener(this);
radio38 = new JRadioButton("rg038", false);
cbg.add(radio38);
getContentPane().add(radio38);
radio38.addActionListener(this);
radio37 = new JRadioButton("rg037", false);
cbg.add(radio37);
getContentPane().add(radio37);
radio37.addActionListener(this);
radio36 = new JRadioButton("rg036", false);
cbg.add(radio36);
getContentPane().add(radio36);
radio36.addActionListener(this);
radio35 = new JRadioButton("rg035", false);
cbg.add(radio35);
getContentPane().add(radio35);
radio35.addActionListener(this);
radio34 = new JRadioButton("rg034", false);
cbg.add(radio34);
getContentPane().add(radio34);
radio34.addActionListener(this);
radio33 = new JRadioButton("rg033", false);
cbg.add(radio33);
getContentPane().add(radio33);
radio33.addActionListener(this);
radio32 = new JRadioButton("rg032", false);
cbg.add(radio32);
getContentPane().add(radio32);
radio32.addActionListener(this);
radio31 = new JRadioButton("rg031", false);
cbg.add(radio31);
getContentPane().add(radio31);
radio31.addActionListener(this);
radio30 = new JRadioButton("rg030", false);
cbg.add(radio30);
getContentPane().add(radio30);
radio30.addActionListener(this);
radio29 = new JRadioButton("rg029", false);
cbg.add(radio29);
getContentPane().add(radio29);
radio29.addActionListener(this);
radio28 = new JRadioButton("rg028", false);
cbg.add(radio28);
getContentPane().add(radio28);
radio28.addActionListener(this);
radio27 = new JRadioButton("rg027", false);
cbg.add(radio27);
getContentPane().add(radio27);
radio27.addActionListener(this);
radio26 = new JRadioButton("rg026", false);
cbg.add(radio26);
getContentPane().add(radio26);
radio26.addActionListener(this);
radio25 = new JRadioButton("rg025", false);
cbg.add(radio25);
getContentPane().add(radio25);
radio25.addActionListener(this);
radio24 = new JRadioButton("rg024", false);
cbg.add(radio24);
getContentPane().add(radio24);
radio24.addActionListener(this);
radio23 = new JRadioButton("rg023", false);
cbg.add(radio23);
getContentPane().add(radio23);
radio23.addActionListener(this);
radio22 = new JRadioButton("rg022", false);
cbg.add(radio22);
getContentPane().add(radio22);
radio22.addActionListener(this);
radio21 = new JRadioButton("rg021", false);
cbg.add(radio21);
getContentPane().add(radio21);
radio21.addActionListener(this);
radio20 = new JRadioButton("rg020", false);
cbg.add(radio20);
getContentPane().add(radio20);
radio20.addActionListener(this);
radio19 = new JRadioButton("rg019", false);
cbg.add(radio19);
getContentPane().add(radio19);
radio19.addActionListener(this);
radio18 = new JRadioButton("rg018", false);
cbg.add(radio18);
getContentPane().add(radio18);
radio18.addActionListener(this);
radio17 = new JRadioButton("rg017", false);
cbg.add(radio17);
getContentPane().add(radio17);
radio17.addActionListener(this);
radio16 = new JRadioButton("rg016", false);
cbg.add(radio16);
getContentPane().add(radio16);
radio16.addActionListener(this);
radio15 = new JRadioButton("rg015", false);
cbg.add(radio15);
getContentPane().add(radio15);
radio15.addActionListener(this);
radio14 = new JRadioButton("rg014", false);
cbg.add(radio14);
getContentPane().add(radio14);
radio14.addActionListener(this);
radio13 = new JRadioButton("rg013", false);
cbg.add(radio13);
getContentPane().add(radio13);
radio13.addActionListener(this);
radio12 = new JRadioButton("rg012", false);
cbg.add(radio12);
getContentPane().add(radio12);
          radio12.addActionListener(this);
radio11 = new JRadioButton("rg011", false);
cbg.add(radio11);
getContentPane().add(radio11);
          radio11.addActionListener(this);
radio10 = new JRadioButton("rg010", false);
cbg.add(radio10);
getContentPane().add(radio10);
radio10.addActionListener(this);
radio9 = new JRadioButton("rg009", false);
cbg.add(radio9);
getContentPane().add(radio9);
radio9.addActionListener(this);
radio8 = new JRadioButton("rg008", false);
cbg.add(radio8);
getContentPane().add(radio8);
radio8.addActionListener(this);
radio7 = new JRadioButton("rg007", false);
cbg.add(radio7);
getContentPane().add(radio7);
radio7.addActionListener(this);
radio6 = new JRadioButton("rg006", false);
cbg.add(radio6);
getContentPane().add(radio6);
radio6.addActionListener(this);
radio5 = new JRadioButton("rg005", false);
cbg.add(radio5);
getContentPane().add(radio5);
radio5.addActionListener(this);
radio4 = new JRadioButton("rg004", false);
cbg.add(radio4);
getContentPane().add(radio4);
radio4.addActionListener(this);
radio3 = new JRadioButton("rg003", false);
cbg.add(radio3);
getContentPane().add(radio3);
radio3.addActionListener(this);
radio2 = new JRadioButton("rg002", false);
cbg.add(radio2);
getContentPane().add(radio2);
radio2.addActionListener(this);
radio1 = new JRadioButton("rg001", false);
cbg.add(radio1);
getContentPane().add(radio1);
radio1.addActionListener(this);
infoLabel1 = new JLabel("Please select from the below excercise codes the exercises that have been generated for");
getContentPane().add(infoLabel1);
infoLabel2 = new JLabel("you and shown in the table, then press submit to view detailed info about each one. ");
getContentPane().add(infoLabel2);
submitButton = new JButton("Submit");
getContentPane().add(submitButton);
submitButton.setToolTipText("Press to view detail about selected exercise");
submitButton.setBackground(Color.white);
submitButton.addActionListener(this);
exitButton = new JButton("Exit");
getContentPane().add(exitButton);
exitButton.setBackground(Color.white);
exitButton.setToolTipText("Press to go back to additional features menu");
exitButton.addActionListener(this);
setSize(getPreferredSize());
setSize(600,680);
show();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
public static void main(String args[]) {
new RunView();
// window.setTitle("RunView");
// window.pack();
// window.show();
          public void actionPerformed(ActionEvent e)
               Object s = e.getSource();
               if(s instanceof JRadioButton)
                    if(s == radio1)
                         exDescription="This Exercise is a continuous short distance exercise which is at a brisk \n"
                                        +"pace however the length is quite short, it is really designed to build up \n"
                                        +"ones endurance, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness building exercise and the main muscle \n"
                                        +"area targetted is the legs,and obviously should help increase stamina and \n"
                                        +"build muscle in the lower region of your body.\n"
                                        +"\nYou should aim to perform this exercise on a daily basis if you are to \n"
                                        +"recieve the results you want. The pace as stated is brisk you should aim \n"
                                        +"to cover from 1000-1500m approx as the duration of the run is 5mins long,\n"
                                        +"and try to set yourslef a target to improve and increase the distance on \n"
                                        +"each run, try to hold form throughout the run, by running at a steady pace \n"
                                        +"one which is not irratic or irregular.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches \n"
                                        +"in legs and calves mainly. Ideally you should normally aim to carry out \n"
                                        +"this run for a minimum 3 week period before returning and performing the \n"
                                        +"exercise review";
                         exCode="rg001";
                    if(s == radio2)
                         exDescription="This Exercise is a continuous short distance exercise which is at a brisk \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness enhancing exercise and the main muscle \n"
                                        +"area targetted are in the legs, and obviously should help build muscle in \n"
                                        +"the lower region of your body. \n"
                                        +"\nYou should aim to perform this exercise on a daily basis if you are to \n"
                                        +"recieve the results you want. The pace as stated is brisk you should aim \n"
                                        +"to cover from 1500-2000m approx as the duration of the run is 10mins long, \n"
                                        +"and try to set yourself a target to improve and increase the distance on \n"
                                        +"each run while the time should remain the same, try to hold form throughout \n"
                                        +"the run, by running at a steady pace one which is not irratic or irregular.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches in\n"
                                        +"should normally aim to carry out this run for a minimum 3 week period \n"
                                        +"legs and calves mainly. Ideally You before returning and performing the\n"
                                        +"exercise review";
                         exCode="rg002";
                    if(s == radio3)
                         exDescription="This Exercise is a continuous short distance exercise which is at a brisk \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness enhancing exercise and the main muscle \n"
                                        +"area targetted are focused on the lower region of your body as a whole \n"
                                        +"because the aim is to strengthen your legs for higher endurance \n"
                                        +"\nYou should aim to perform this exercise on a daily basis if you are to \n"
                                        +"recieve the results you want. The pace as stated is brisk you should aim \n"
                                        +"to cover from 1700-2200m approx as the duration of the run is 12mins long, \n"
                                        +"and try to set yourself a target to improve and increase the distance on \n"
                                        +"each run while the time should remain the same, try to hold form throughout \n"
                                        +"the run, by running at a steady pace one which is not irratic or irregular.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches in\n"
                                        +"legs and calves mainly. Ideally You should normally aim to carry out this \n"
                                        +"run for a minimum 3 week period before returning and performing the\n"
                                        +"exercise review";
                         exCode="rg003";
                    if(s ==radio4)
                         exDescription="This Exercise is a continuous short distance exercise which is at a brisk \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness enhancing exercise and the main muscle \n"
                                        +"area targetted are focused on the lower region of your body as a whole \n"
                                        +"because the aim is to strengthen your legs for higher endurance \n"
                                        +"\nYou should aim to perform this exercise on a daily basis if you are to \n"
                                        +"recieve the results you want. The pace as stated is brisk you should aim \n"
                                        +"to cover from 1700-2200m approx as the duration of the run is 15mins long, \n"
                                        +"and try to set yourself a target to improve and increase the distance on \n"
                                        +"each run while the time should remain the same, try to hold form throughout \n"
                                        +"the run, by running at a steady pace one which is not irratic or irregular.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches in\n"
                                        +"legs and calves mainly. Ideally You should normally aim to carry out this \n"
                                        +"run for a minimum 3 week period before returning and performing the\n"
                                        +"exercise review";
                         exCode="rg004";          
                    if(s ==radio5)
                         exDescription="rg005 is a continuous short distance exercise which is at a moderate \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness enhancing exercise and the main muscle \n"
                                        +"area targetted are focused on the lower region of your body as a whole \n"
                                        +"because the aim is to strengthen your legs for higher endurance \n"
                                        +"\nYou should aim to perform this exercise on a daily basis if you are to \n"
                                        +"recieve the results you want. The pace is moderate and you should aim \n"
                                        +"to cover from 2000-2200m approx as the duration of the run is 20mins long, \n"
                                        +"and try to set yourself a target to improve and increase the distance on \n"
                                        +"each run while the time should remain the same, try to hold form throughout \n"
                                        +"the run, by running at a steady pace one which is not irratic or irregular.\n"
                                        +"done correctly this exercise should reduce you fat levels progressively and\n"
                                        +"improve your fitness by ample amounts, but the longer the run is the more \n"
                                        +"emphasis is placed on keeping motivated and not stopping in duration no \n"
                                        +"matter how exausted you may feel.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches in\n"
                                        +"legs and calves mainly. Ideally You should normally aim to carry out this \n"
                                        +"run for a minimum 3 week period before returning and performing the\n"
                                        +"exercise review";
                         exCode="rg005";
                    if(s ==radio6)
                         exDescription="rg006 is a continuous short distance exercise which is at a moderate \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness enhancing exercise and the main muscle \n"
                                        +"area targetted are focused on the lower region of your body as a whole \n"
                                        +"because the aim is to strengthen your legs for higher endurance \n"
                                        +"\nYou should aim to perform this exercise 4 times a week if you are to \n"
                                        +"recieve the results you want. The pace is moderate and you should aim \n"
                                        +"to cover from 2200-2500m approx as the duration of the run is 25mins long, \n"
                                        +"and try to set yourself a target to improve and increase the distance on \n"
                                        +"each run while the time should remain the same, try to hold form throughout \n"
                                        +"the run, by running at a steady pace one which is not irratic or irregular.\n"
                                        +"done correctly this exercise should reduce you fat levels progressively and\n"
                                        +"improve your fitness by ample amounts, but the longer the run is the more \n"
                                        +"emphasis is placed on keeping motivated and not stopping in duration no \n"
                                        +"matter how exausted you may feel.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches in\n"
                                        +"legs and calves mainly. Ideally You should normally aim to carry out this \n"
                                        +"run for a minimum 3 week period before returning and performing the\n"
                                        +"exercise review";
                         exCode="rg006";
                    if(s ==radio7)
                         exDescription="This Exercise is a continuous short distance exercise which is at a slow \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"
                                        +"\nThe exercise itself is a fitness enhancing exercise and the main muscle \n"
                                        +"area targetted are focused on the lower region of your body as a whole \n"
                                        +"because the aim is to strengthen your legs for higher endurance \n"
                                        +"\nIn addtion there is the added bonus of benifitting from a high level of \n"
                                        +"stamina and good performance under stress as this exercise will increase \n"
                                        +"you mental toughness as you push yourself\n"
                                        +"\nYou should aim to perform this exercise 4 times a week if you are to \n"
                                        +"recieve the results you want. The pace as stated is slow and you should aim \n"
                                        +"to cover from 2000-2200m approx as the duration of the run is 30mins long, \n"
                                        +"and try to set yourself a target to improve and increase the distance on \n"
                                        +"each run while the time should remain the same, try to hold form throughout \n"
                                        +"the run, by running at a steady pace one which is not irratic or irregular.\n"
                                        +"done correctly this exercise should reduce you fat levels progressively and\n"
                                        +"improve your fitness by ample amounts, but the longer the run is the more \n"
                                        +"emphasis is placed on keeping motivated and not stopping in duration no \n"
                                        +"matter how exausted you may feel.\n"
                                        +"\nplease ensure you worm up properly by doin all the nececary stretches in\n"
                                        +"legs and calves mainly. Ideally You should normally aim to carry out this \n"
                                        +"run for a minimum 3 week period before returning and performing the review";
                         exCode="rg007";
                    if(s ==radio8)
                         exDescription="This Exercise is a continuous long distance exercise which is at a slow \n"
                                        +"pace however the length is short, it is really designed to build up \n"
                                        +"ones endurance and stamina levels, and should be done outdoors ideally. \n"

Use this class to print your contentPane of your
JFrame:
import java.awt.*;
import java.awt.geom.*;
import java.awt.print.*;
import javax.swing.*;
public class ComponenteParaImprimir
implements Printable {
private Component mComponent;
boolean isBook;
boolean escala;
boolean visible;
public final static boolean PARA_BOOK = true;
public final static boolean HARDCOPY = false;
public final static boolean CON_ESCALADO = true;
public final static boolean SIN_ESCALADO = false;
public final static boolean VISIBLE = true;
public final static boolean INVISIBLE = false;
static JFrame invisibleContainer;
public ComponenteParaImprimir(Component c, boolean
book, boolean escala,
boolean visible) {
mComponent = c;
isBook = book;
this.escala = escala;
this.visible = visible;
public int print(Graphics g, PageFormat pageFormat,
int pageIndex) {
if (pageIndex > 0 && !isBook) {
return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
AffineTransform oldTransform = g2.getTransform();
double x0 = pageFormat.getImageableX(), y0 =
pageFormat.getImageableY();
double pw = pageFormat.getImageableWidth(),
ph = pageFormat.getImageableHeight();
g2.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
int cw = mComponent.getWidth(), ch =
mComponent.getHeight();
double scx = ( (double) pw) / cw;
double scy = ( (double) ph) / ch;
if (escala) {
g2.scale(scx, scy);
if (!visible) {
if (invisibleContainer == null) {
//obtener tama�o del frame
invisibleContainer = new JFrame();
invisibleContainer.getContentPane().add(mComponent);
invisibleContainer.pack();
invisibleContainer.setVisible(false);
invisibleContainer.getContentPane().removeAll();
invisibleContainer.getContentPane().add(mComponent);
invisibleContainer.pack();
invisibleContainer.setVisible(false);
setDoubleBuffering(mComponent, false);
mComponent.paint(g2);
setDoubleBuffering(mComponent, true);
g2.setTransform(oldTransform);
return PAGE_EXISTS;
public void limpiaPanelInvisible() {
invisibleContainer.getContentPane().removeAll();
invisibleContainer = null;
private boolean disableDoubleBuffering(Component c) {
if (c instanceof JComponent == false) {
return false;
JComponent jc = (JComponent) c;
boolean wasBuffered = jc.isDoubleBuffered();
jc.setDoubleBuffered(false);
return wasBuffered;
private void restoreDoubleBuffering(Component c,
boolean wasBuffered) {
if (c instanceof JComponent) {
( (JComponent) c).setDoubleBuffered(wasBuffered);
private void setDoubleBuffering(Component c, boolean
isEnabled) {
RepaintManager manager =
RepaintManager.currentManager(c);
manager.setDoubleBufferingEnabled(isEnabled);
use it lyke this : transform your contentPane to
printable whith visible parameter to false....
ComponenteParaImprimir cp = new
ComponenteParaImprimir( (JPanel)
this.getContentPane(),false,true,false);
PageFormat pf = pj.defaultPage();
attributes = new HashPrintRequestAttributeSet();
attributes.add(MediaSizeName.ISO_A4);
attributes.add(new MediaPrintableArea(5, 5, 200, 300,
MediaPrintableArea.MM));
Paper papel = new Paper();
pf.setPaper(papel);
pf.setOrientation(PageFormat.LANDSCAPE);
pj.setPrintable(cp, pf);
if (pj.printDialog()) {
try {
pj.print(attributes);
catch (PrinterException pe) {
System.out.println(pe);
i hope its helps you...hi thanks very much for your help. but i do not understand how to implement the last piece of code you have included.. is this sopose to go in my original class? please indicate where i need to put it .. thanks for your assistance

Similar Messages

  • Can't print JFrame

    Hi,
    i am trying to print out a JFrame that contains other Swing and AWT components, such as JTables and menus etc.
    The problem is that the options that i select from the pageformat dialog, so not get set when the printing is taking place. As a result my jframe gets cut up into 4 differnet bits and each comes out on a seperate page. I cannot specify number of copies or size of paper either. Also once the ok button is pressed on the print dialogue, then the print dialogue comes back again and i have to press Ok, or Cancel to get rid of it. My code is below, please can someone suggest anything:
    ]public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
              if (pi >= 1)
                   return Printable.NO_SUCH_PAGE;
              Graphics2D g2 = (Graphics2D) g;
              g2.translate(pf.getImageableX(), pf.getImageableY());
              g2.setColor(Color.black);
              paint(g2);
              return Printable.PAGE_EXISTS;
    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = pjob.defaultPage();
    pjob.setPrintable(TransponderGraph.this, pf);
    try
    pjob.print();
    catch (PrinterException e) { }

    Just comment this line frame.setAlwaysOnTop(x);

  • Problem with printing JFrame with several other components on it

    Hi,
    i am trying to print out a JFrame that contains other Swing and AWT components, such as JTables and menus etc.
    The problem is that the options that i select from the pageformat dialog, do not get set when the printing is taking place. As a result my jframe gets cut up into 4 differnet bits and each comes out on a seperate page. I cannot specify number of copies or size of paper either. Also once the ok button is pressed on the print dialogue, then the print dialogue comes back again and i have to press Ok, or Cancel to get rid of it. My code is below, please can someone suggest anything:
    ]public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
    if (pi >= 1)
    return Printable.NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(pf.getImageableX(), pf.getImageableY());
    g2.setColor(Color.black);
    paint(g2);
    return Printable.PAGE_EXISTS;
    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = pjob.defaultPage();
    pjob.setPrintable(TransponderGraph.this, pf);
    try
    pjob.print();
    catch (PrinterException e) { }

    Ok, try this.
    Change this:
    <link href="
    http://www.jonbarron.org/css/style.css"
    rel="stylesheet" type="text/css" />
    to this:
    <link href="
    http://www.jonbarron.org/css/style.css"
    rel="stylesheet" type="text/css" media="screen" />
    Somewhere in that stylesheet lies your problem.

  • Print JFrame without title bar and border

    I am trying to print out a JFrame which contains two JPanels. The following code is part of my implementation of Printable which prints the entire JFrame including the title bar and border. I've considered implementing Printable in the JPanel classes but then I don't know how I would get everything on one page as a single image. Is there some way to just print the contentPane of the JFrame?
         public int print(Graphics g, PageFormat pf, int pi)
              throws PrinterException {
              if (pi >= 1) {
                   return Printable.NO_SUCH_PAGE;
              Graphics2D g2 = (Graphics2D) g;
              double scaleX = pf.getImageableWidth()/getWidth();
              double scaleY = pf.getImageableHeight()/getHeight();
              double scale = 1;
              g2.translate((int) pf.getImageableX(), (int) pf.getImageableY());
              if (scaleX < 1 || scaleY < 1) {
                   scale = scaleX < scaleY ? scaleX : scaleY;
                   g2.scale(scale,scale);
              printAll(g2);
              return Printable.PAGE_EXISTS;
         }                    

    Thanks.
    I can get the Jframe without the title bar and I can get it to drag on the desktop with your suggestions. I still need it to have rounded edges.

  • Help needed:Printing HTML file using javax.print

    Hi
    I am using the following code which i got form the forum for rpinting an HTML file.
    The folllowing code is working fine, but the problem is the content of HTML file is not getting printed. I am geeting a blank page with no content. What is the change that is required in the code? ALso is there any simpler way to implement this. Help needed ASAP.
    public boolean printHTMLFile(String filename) {
              try {
                   JEditorPane editorPane = new JEditorPane();
                   editorPane.setEditorKit(new HTMLEditorKit());
                   //editorPane.setContentType("text/html");
                   editorPane.setSize(500,500);
                   String text = getFileContents(filename);
                   if (text != null) {
                        editorPane.setText(text);                    
                   } else {
                        return false;
                   printEditorPane(editorPane);
                   return true;
              } catch (Exception tce) {
                   tce.printStackTrace();
              return false;
         public String getFileContents(String filename) {
              try {
                   File file = new File(filename);
                   BufferedReader br = new BufferedReader(new FileReader(file));
                   String line;
                   StringBuffer sb = new StringBuffer();
                   while ((line = br.readLine()) != null) {
                        sb.append(line);
                   br.close();
                   return sb.toString();
              } catch (Exception tce) {
                   tce.printStackTrace();
              return null;
         public void printEditorPane(JEditorPane editorPane) {
                   try {
                        HTMLPrinter htmlPrinter = new HTMLPrinter();
                        htmlPrinter.printJEditorPane(editorPane, htmlPrinter.showPrintDialog());
                   } catch (Exception tce) {
                        tce.printStackTrace();
         * Sets up to easily print HTML documents. It is not necessary to call any of the setter
         * methods as they all have default values, they are provided should you wish to change
         * any of the default values.
         public class HTMLPrinter {
         public int DEFAULT_DPI = 72;
         public float DEFAULT_PAGE_WIDTH_INCH = 8.5f;
         public float DEFAULT_PAGE_HEIGHT_INCH = 11f;
         int x = 100;
         int y = 80;
         GraphicsConfiguration gc;
         PrintService[] services;
         PrintService defaultService;
         DocFlavor flavor;
         PrintRequestAttributeSet attributes;
         Vector pjlListeners = new Vector();
         Vector pjalListeners = new Vector();
         Vector psalListeners = new Vector();
         public HTMLPrinter() {
              gc = null;
              attributes = new HashPrintRequestAttributeSet();
              flavor = null;
              defaultService = PrintServiceLookup.lookupDefaultPrintService();
              services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
              // do something with the supported docflavors
              DocFlavor[] df = defaultService.getSupportedDocFlavors();
              for (int i = 0; i < df.length; i++)
              System.out.println(df.getMimeType() + " " + df[i].getRepresentationClassName());
              // if there is a default service, but no other services
              if (defaultService != null && (services == null || services.length == 0)) {
              services = new PrintService[1];
              services[0] = defaultService;
         * Set the GraphicsConfiguration to display the print dialog on.
         * @param gc a GraphicsConfiguration object
         public void setGraphicsConfiguration(GraphicsConfiguration gc) {
              this.gc = gc;
         public void setServices(PrintService[] services) {
              this.services = services;
         public void setDefaultService(PrintService service) {
              this.defaultService = service;
         public void setDocFlavor(DocFlavor flavor) {
              this.flavor = flavor;
         public void setPrintRequestAttributes(PrintRequestAttributeSet attributes) {
              this.attributes = attributes;
         public void setPrintDialogLocation(int x, int y) {
              this.x = x;
              this.y = y;
         public void addPrintJobListener(PrintJobListener pjl) {
              pjlListeners.addElement(pjl);
         public void removePrintJobListener(PrintJobListener pjl) {
              pjlListeners.removeElement(pjl);
         public void addPrintServiceAttributeListener(PrintServiceAttributeListener psal) {
              psalListeners.addElement(psal);
         public void removePrintServiceAttributeListener(PrintServiceAttributeListener psal) {
              psalListeners.removeElement(psal);
         public boolean printJEditorPane(JEditorPane jep, PrintService ps) {
                   if (ps == null || jep == null) {
                        System.out.println("printJEditorPane: jep or ps is NULL, aborting...");
                        return false;
                   // get the root view of the preview pane
                   View rv = jep.getUI().getRootView(jep);
                   // get the size of the view (hopefully the total size of the page to be printed
                   int x = (int) rv.getPreferredSpan(View.X_AXIS);
                   int y = (int) rv.getPreferredSpan(View.Y_AXIS);
                   // find out if the print has been set to colour mode
                   DocPrintJob dpj = ps.createPrintJob();
                   PrintJobAttributeSet pjas = dpj.getAttributes();
                   // get the DPI and printable area of the page. use default values if not available
                   // use this to get the maximum number of pixels on the vertical axis
                   PrinterResolution pr = (PrinterResolution) pjas.get(PrinterResolution.class);
                   int dpi;
                   float pageX, pageY;
                   if (pr != null)
                        dpi = pr.getFeedResolution(PrinterResolution.DPI);
                   else
                        dpi = DEFAULT_DPI;
                   MediaPrintableArea mpa = (MediaPrintableArea) pjas.get(MediaPrintableArea.class);
                   if (mpa != null) {
                        pageX = mpa.getX(MediaPrintableArea.INCH);
                        pageY = mpa.getX(MediaPrintableArea.INCH);
                   } else {
                        pageX = DEFAULT_PAGE_WIDTH_INCH;
                        pageY = DEFAULT_PAGE_HEIGHT_INCH;
                   int pixelsPerPageY = (int) (dpi * pageY);
                   int pixelsPerPageX = (int) (dpi * pageX);
                   int minY = Math.max(pixelsPerPageY, y);
                   // make colour true if the user has selected colour, and the PrintService can support colour
                   boolean colour = pjas.containsValue(Chromaticity.COLOR);
                   colour = colour & (ps.getAttribute(ColorSupported.class) == ColorSupported.SUPPORTED);
                   // create a BufferedImage to draw on
                   int imgMode;
                   if (colour)
                        imgMode = BufferedImage.TYPE_3BYTE_BGR;
                   else
                        imgMode = BufferedImage.TYPE_BYTE_GRAY;
                   BufferedImage img = new BufferedImage(pixelsPerPageX, minY, imgMode);
                   Graphics myGraphics = img.getGraphics();
                   myGraphics.setClip(0, 0, pixelsPerPageX, minY);
                   myGraphics.setColor(Color.WHITE);
                   myGraphics.fillRect(0, 0, pixelsPerPageX, minY);
                        java.awt.Rectangle rectangle=new java.awt.Rectangle(0,0,pixelsPerPageX, minY);
                   // call rootView.paint( myGraphics, rect ) to paint the whole image on myGraphics
                   rv.paint(myGraphics, rectangle);
                   try {
                        // write the image as a JPEG to the ByteArray so it can be printed
                        Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
                        ImageWriter writer = (ImageWriter) writers.next();
                                       // mod: Added the iwparam to create the highest quality image possible
                        ImageWriteParam iwparam = writer.getDefaultWriteParam();
                        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
                        iwparam.setCompressionQuality(1.0f); // highest quality
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        ImageOutputStream ios = ImageIO.createImageOutputStream(out);
                        writer.setOutput(ios);
                        // get the number of pages we need to print this image
                        int imageHeight = img.getHeight();
                        int numberOfPages = (int) Math.ceil(minY / (double) pixelsPerPageY);
                        // print each page
                        for (int i = 0; i < numberOfPages; i++) {
                             int startY = i * pixelsPerPageY;
                             // get a subimage which is exactly the size of one page
                             BufferedImage subImg = img.getSubimage(0, startY, pixelsPerPageX, Math.min(y - startY, pixelsPerPageY));
                                                 // mod: different .write() method to use the iwparam parameter with highest quality compression
                             writer.write(null, new IIOImage(subImg, null, null), iwparam);
                             SimpleDoc sd = new SimpleDoc(out.toByteArray(), DocFlavor.BYTE_ARRAY.JPEG, null);
                             printDocument(sd, ps);
                             // reset the ByteArray so we can start the next page
                             out.reset();
                   } catch (PrintException e) {
                        System.out.println("Error printing document.");
                        e.printStackTrace();
                        return false;
                   } catch (IOException e) {
                        System.out.println("Error creating ImageOutputStream or writing to it.");
                        e.printStackTrace();
                        return false;
                   // uncomment this code and comment out the 'try-catch' block above
                   // to print to a JFrame instead of to the printer
                   /*          JFrame jf = new JFrame();
                             PaintableJPanel jp = new PaintableJPanel();
                             jp.setImage( img );
                             JScrollPane jsp = new JScrollPane( jp );
                             jf.getContentPane().add( jsp );
                             Insets i = jf.getInsets();
                             jf.setBounds( 0, 0, newX, y );
                             jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
                             jf.setVisible( true );*/
                   return true;
              * Print the document to the specified PrintService.
              * This method cannot tell if the printing was successful. You must register
              * a PrintJobListener
              * @return false if no PrintService is selected in the dialog, true otherwise
              public boolean printDocument(Doc doc, PrintService ps) throws PrintException {
                   if (ps == null)
                   return false;
                   addAllPrintServiceAttributeListeners(ps);
                   DocPrintJob dpj = ps.createPrintJob();
                   addAllPrintJobListeners(dpj);
                   dpj.print(doc, attributes);
                   return true;
              public PrintService showPrintDialog() {
                   return ServiceUI.printDialog(gc, x, y, services, defaultService, flavor, attributes);
              private void addAllPrintServiceAttributeListeners(PrintService ps) {
                   // add all listeners that are currently added to this object
                   for (int i = 0; i < psalListeners.size(); i++) {
                   PrintServiceAttributeListener p = (PrintServiceAttributeListener) psalListeners.get(i);
                   ps.addPrintServiceAttributeListener(p);
              private void addAllPrintJobListeners(DocPrintJob dpj) {
                   // add all listeners that are currently added to this object
                   for (int i = 0; i < pjlListeners.size(); i++) {
                   PrintJobListener p = (PrintJobListener) pjlListeners.get(i);
                   dpj.addPrintJobListener(p);
              // uncomment this also to print to a JFrame instead of a printer
              /* protected class PaintableJPanel extends JPanel {
                   Image img;
                   protected PaintableJPanel() {
                        super();
                   public void setImage( Image i ) {
                        img = i;
                   public void paint( Graphics g ) {
                        g.drawImage( img, 0, 0, this );
    Thanks
    Ram

    Ram,
    I have had printing problems too a year and a half ago. I used all printing apis of java and I still find that it is something java lacks. Now basically you can try autosense. To check whether your printer is capable of printing the docflavor use this PrintServiceLookup.lookupPrintServices(flavor, aset); . If it lists the printer then he can print the document otherwise he can't. I guess that is why you get the error.
    Regards,
    Kevin

  • How to print jEditorPane content

    Hi,
    I have got the html content in jeditorPane and i wanted to print the content to the printer in landscape mode. can any one help me out?, I appreciate your time . Infact i did see an example here but when i started running it, i could end up no where.
    Thanks,
    krishna

    infact the example i saw in this forum, rythos , is the author but i could not make the code he posted there working. I would appreciate if some one can take interest into it.
    Below is the Rythos Code :
    import javax.swing.*;import java.awt.*;import java.awt.image.*;import java.io.*;import java.util.*;import javax.print.*;import javax.print.attribute.*;import javax.print.attribute.standard.*;import javax.print.event.*;import javax.swing.text.*;import javax.imageio.*;import javax.imageio.stream.*;/** * Sets up to easily print HTML documents. It is not necessary to call any of the setter * methods as they all have default values, they are provided should you wish to change * any of the default values.*/public class Printer {     public static int DEFAULT_DPI = 72;     public static float DEFAULT_PAGE_WIDTH_INCH = 8.5f;     public static float DEFAULT_PAGE_HEIGHT_INCH = 11f;     int x = 100;     int y = 80;     GraphicsConfiguration gc;     PrintService[] services;     PrintService defaultService;     DocFlavor flavor;     PrintRequestAttributeSet attributes;     Vector pjlListeners = new Vector();     Vector pjalListeners = new Vector();     Vector psalListeners = new Vector();     public Printer() {          gc = null;          attributes = new HashPrintRequestAttributeSet();          flavor = null;          defaultService = PrintServiceLookup.lookupDefaultPrintService();          services = PrintServiceLookup.lookupPrintServices( flavor, attributes );          // do something with the supported docflavors          DocFlavor[] df = defaultService.getSupportedDocFlavors();          for( int i = 0; i < df.length; i++ )               System.out.println( df.getMimeType() + " " + df[i].getRepresentationClassName() );          // if there is a default service, but no other services          if( defaultService != null && ( services == null || services.length == 0 ) ) {               services = new PrintService[1];               services[0] = defaultService;          }     }     /**     * Set the GraphicsConfiguration to display the print dialog on.     *     * @param gc a GraphicsConfiguration object     */     public void setGraphicsConfiguration( GraphicsConfiguration gc ) {          this.gc = gc;     }     public void setServices( PrintService[] services ) {          this.services = services;     }     public void setDefaultService( PrintService service ) {          this.defaultService = service;     }     public void setDocFlavor( DocFlavor flavor ) {          this.flavor = flavor;     }     public void setPrintRequestAttributes( PrintRequestAttributeSet attributes ) {          this.attributes = attributes;     }     public void setPrintDialogLocation( int x, int y ) {          this.x = x;          this.y = y;     }     public void addPrintJobListener( PrintJobListener pjl ) {          pjlListeners.addElement( pjl );     }     public void removePrintJobListener( PrintJobListener pjl ) {          pjlListeners.removeElement( pjl );     }     public void addPrintServiceAttributeListener( PrintServiceAttributeListener psal ) {          psalListeners.addElement( psal );     }     public void removePrintServiceAttributeListener( PrintServiceAttributeListener psal ) {          psalListeners.removeElement( psal );     }     public boolean printJEditorPane( JEditorPane jep, PrintService ps ) {          if( ps == null || jep == null ) return false;          // get the root view of the preview pane          View rv = jep.getUI().getRootView( jep );          // get the size of the view (hopefully the total size of the page to be printed          int x = ( int ) rv.getPreferredSpan( View.X_AXIS );          int y = ( int ) rv.getPreferredSpan( View.Y_AXIS );          // find out if the print has been set to colour mode          DocPrintJob dpj = ps.createPrintJob();          PrintJobAttributeSet pjas = dpj.getAttributes();          // get the DPI and printable area of the page. use default values if not available          // use this to get the maximum number of pixels on the vertical axis          PrinterResolution pr = ( PrinterResolution ) pjas.get( PrinterResolution.class );          int dpi;          float pageX, pageY;          if( pr != null ) dpi = pr.getFeedResolution( PrinterResolution.DPI );          else dpi = DEFAULT_DPI;          MediaPrintableArea mpa = ( MediaPrintableArea ) pjas.get( MediaPrintableArea.class );          if( mpa != null ) {               pageX = mpa.getX( MediaPrintableArea.INCH );               pageY = mpa.getX( MediaPrintableArea.INCH );          } else {               pageX = DEFAULT_PAGE_WIDTH_INCH;               pageY = DEFAULT_PAGE_HEIGHT_INCH;          }          int pixelsPerPageY = ( int ) ( dpi * pageY );          // make colour true if the user has selected colour, and the PrintService can support colour          boolean colour = pjas.containsValue( Chromaticity.COLOR );          colour = colour & ( ps.getAttribute( ColorSupported.class ) == ColorSupported.SUPPORTED );          // create a BufferedImage to draw on          int imgMode;          if( colour ) imgMode = BufferedImage.TYPE_3BYTE_BGR;          else imgMode = BufferedImage.TYPE_BYTE_GRAY;          BufferedImage img = new BufferedImage( x, y, imgMode );          Graphics myGraphics = img.getGraphics();          myGraphics.setClip( 0, 0, x, y );          myGraphics.setColor( Color.WHITE );          myGraphics.fillRect( 0, 0, x, y );          // call rootView.paint( myGraphics, rect ) to paint the whole image on myGraphics          rv.paint( myGraphics, new Rectangle( 0, 0, x, y ) );           try {               // write the image as a JPEG to the ByteArray so it can be printed                Iterator writers = ImageIO.getImageWritersByFormatName( "jpeg" );               ImageWriter writer = ( ImageWriter ) writers.next();               ByteArrayOutputStream out = new ByteArrayOutputStream();               ImageOutputStream ios = ImageIO.createImageOutputStream( out );               writer.setOutput( ios );               // get the number of pages we need to print this image               int imageHeight = img.getHeight();               int numberOfPages = ( int ) ( ( imageHeight / pixelsPerPageY ) + 0.5 );               // print each page               for( int i = 0; i < numberOfPages; i++ ) {                    int startY = i * pixelsPerPageY;                                        // get a subimage which is exactly the size of one page                    BufferedImage subImg = img.getSubimage( 0, startY, x, pixelsPerPageY );                    writer.write( subImg );                    SimpleDoc sd = new SimpleDoc( out.toByteArray(), DocFlavor.BYTE_ARRAY.JPEG, null );                    printDocument( sd, ps );                    // reset the ByteArray so we can start the next page                    out.reset();               }          } catch( PrintException e ) {               System.out.println( "Error printing document." );               e.printStackTrace();               return false;          } catch( IOException e ) {               System.out.println( "Error creating ImageOutputStream or writing to it." );               e.printStackTrace();               return false;          }          // uncomment this code and comment out the 'try-catch' block above          // to print to a JFrame instead of to the printer/*          JFrame jf = new JFrame();          PaintableJPanel jp = new PaintableJPanel();          jp.setImage( img );          JScrollPane jsp = new JScrollPane( jp );          jf.getContentPane().add( jsp );          Insets i = jf.getInsets();          jf.setBounds( 0, 0, newX, y );          jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );          jf.setVisible( true );*/          return true;     }     /**     * Print the document to the specified PrintService.     * This method cannot tell if the printing was successful. You must register     * a PrintJobListener      *     * @return false if no PrintService is selected in the dialog, true otherwise     */     public boolean printDocument( Doc doc, PrintService ps ) throws PrintException {          if( ps == null ) return false;          addAllPrintServiceAttributeListeners( ps );          DocPrintJob dpj = ps.createPrintJob();          addAllPrintJobListeners( dpj );          dpj.print( doc, attributes );          return true;     }     public PrintService showPrintDialog() {          return ServiceUI.printDialog(                gc, x, y, services, defaultService, flavor, attributes );     }     private void addAllPrintServiceAttributeListeners( PrintService ps ) {          // add all listeners that are currently added to this object           for( int i = 0; i < psalListeners.size(); i++ ) {               PrintServiceAttributeListener p = ( PrintServiceAttributeListener ) psalListeners.get( i );               ps.addPrintServiceAttributeListener( p );          }     }     private void addAllPrintJobListeners( DocPrintJob dpj ) {          // add all listeners that are currently added to this object           for( int i = 0; i < pjlListeners.size(); i++ ) {               PrintJobListener p = ( PrintJobListener ) pjlListeners.get( i );               dpj.addPrintJobListener( p );          }     }     // uncomment this also to print to a JFrame instead of a printer/*     protected class PaintableJPanel extends JPanel {          Image img;          protected PaintableJPanel() {               super();          }          public void setImage( Image i ) {               img = i;          }                    public void paint( Graphics g ) {               g.drawImage( img, 0, 0, this );                         }     }*/}

  • Which rows/columns could be seen in scrollpane?

    hi, there,
    I have a large table. whenever I scroll the scrollbar, I'd like to know which part the table is visible. How could I do that?
    Any help will be greatly appreciated.
    Jim

    Code?
    BTW, if you're using 1.5, print() is a JTable method:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.PrinterException;
    import javax.swing.*;
    public class PrintTest {
        public static void main(String[] args) throws PrinterException {
            Object[] columnNames = {"first name", "last name", "hair"};
            Object[][] data = {
                {"Homer","Simpson","sparse"},
                {"Marge","Simpson","blue"},
                {"Crusty","Clown","tufts"}
            final JTable table = new JTable(data, columnNames);
            JButton print = new JButton("print");
            print.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    try {
                        table.print();
                    } catch (PrinterException e) {
                        e.printStackTrace();
            JPanel south = new JPanel();
            south.add(print);
            JFrame f = new JFrame("PrintTest");
            Container cp = f.getContentPane();
            cp.add(new JScrollPane(table));
            cp.add(south, BorderLayout.SOUTH);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • How to print the whole JFrame

    Hi,
    I got this code somewhere from the net.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    /** A simple utility class that lets you very simply print
    *  an arbitrary component. Just pass the component to the
    *  PrintUtilities.printComponent. The component you want to
    *  print doesn't need a print method and doesn't have to
    *  implement any interface or do anything special at all.
    *  <P>
    *  If you are going to be printing many times, it is marginally more
    *  efficient to first do the following:
    *  <PRE>
    *    PrintUtilities printHelper = new PrintUtilities(theComponent);
    *  </PRE>
    *  then later do printHelper.print(). But this is a very tiny
    *  difference, so in most cases just do the simpler
    *  PrintUtilities.printComponent(componentToBePrinted).
    *  7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
    *  May be freely used or adapted.
    public class PrintUtilities implements Printable {
      private JFrame componentToBePrinted;
      public static void printComponent(JFrame c) {
        new PrintUtilities(c).print();
      public PrintUtilities(JFrame componentToBePrinted) {
        this.componentToBePrinted = componentToBePrinted;
      public void print() {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        if (printJob.printDialog())
          try {
            printJob.print();
          } catch(PrinterException pe) {
            System.out.println("Error printing: " + pe);
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex > 0) {
          return(NO_SUCH_PAGE);
        } else {
          Graphics2D g2d = (Graphics2D)g;
          g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
          disableDoubleBuffering(componentToBePrinted);
          componentToBePrinted.paint(g2d);
          enableDoubleBuffering(componentToBePrinted);
          return(PAGE_EXISTS);
      /** The speed and quality of printing suffers dramatically if
       *  any of the containers have double buffering turned on.
       *  So this turns if off globally.
       *  @see enableDoubleBuffering
      public static void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
      /** Re-enables double buffering globally. */
      public static void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
    }From my main class (where the JFrame resides), the print() method is invoked to print the JFrame. However, when it is printed, it only prints the top left part of the JFrame, not the whole JFrame. Can anyone help please? Thank you very much.

    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex > 0) {
          return(NO_SUCH_PAGE);
        else {
          Graphics2D g2d = (Graphics2D)g;     
          g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
           double xScale = 0.63;
           double yScale = 0.56;
          g2d.scale(xScale, yScale);
          disableDoubleBuffering(componentToBePrinted);     
          componentToBePrinted.paint(g2d);
          enableDoubleBuffering(componentToBePrinted);
          return(PAGE_EXISTS);
      }Hi all,
    Alright I managed to scale it to print the whole JFrame. But another problem surfaces. When I select draft quality printing, it doesn't print the whole JFrame. Other printing qualities (standard, high) do print the whole JFrame. I am really puzzled. Anyone has any clue?
    And I have an unrelated question to this topic. How do I set a JTextField so that when I click on it the first time, it highlights its content? Have to work around with the mouselistener?
    Thank you.

  • How to print the JFrame In The Center Of The Page?

    hi there in the following code iam trying to print a JFrame
    but the frame appear in the printed page at the top left
    and i want it to appear in the top center of the page
    how to do that?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.print.*;
    class PrintUIWindow implements Printable, ActionListener {
        JFrame frameToPrint;
        public int print(Graphics g, PageFormat pf, int page) throws
                                                            PrinterException {
            if (page > 0) {
                return NO_SUCH_PAGE;
            Graphics2D g2d = (Graphics2D)g;
            g2d.translate(pf.getImageableX(), pf.getImageableY()-55);
            frameToPrint.print(g);
            return PAGE_EXISTS;
        public void actionPerformed(ActionEvent e) {
             PrinterJob job = PrinterJob.getPrinterJob();
             job.setPrintable(this);
             boolean ok = job.printDialog();
             if (ok) {
                 try {
                      job.print();
                 } catch (PrinterException ex) {
        public PrintUIWindow(JFrame f) {
            frameToPrint = f;
        public static void main(String args[]) {
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            JFrame f = new JFrame("Print UI Example");
            f.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {System.exit(0);}
            JLabel label1=new JLabel("Selling Bill",JLabel.CENTER);
            JLabel label2=new JLabel("Customer Name :Mahmoud Saleh       ",JLabel.LEFT);
            JLabel label3=new JLabel("Buying Date :29/8/2008             ",JLabel.LEFT);
            JLabel label4=new JLabel("Book Buyed :Java Printing          ",JLabel.LEFT);
            JLabel label5=new JLabel("Number : 6 Copies                  ",JLabel.LEFT);
            JLabel label6=new JLabel("Total Price :600 $                 ",JLabel.LEFT);
            label1.setFont(new Font("Courier New", Font.BOLD, 13));
            label2.setFont(new Font("Courier New", Font.BOLD, 13));
            label3.setFont(new Font("Courier New", Font.BOLD, 13));
            label4.setFont(new Font("Courier New", Font.BOLD, 13));
            label5.setFont(new Font("Courier New", Font.BOLD, 13));
            label6.setFont(new Font("Courier New", Font.BOLD, 13));
            JButton printButton = new JButton("Print This Window");
            printButton.addActionListener(new PrintUIWindow(f));               
            JPanel panel=new JPanel();
            panel.setLayout(new GridLayout(6,1));
            panel.add(label1);
            panel.add(label2);
            panel.add(label3);
            panel.add(label4);
            panel.add(label5);
            panel.add(label6);
            f.setSize(300,300);       
            f.setLocationRelativeTo(null);       
            f.add(panel,BorderLayout.CENTER);
            f.add(printButton,BorderLayout.SOUTH);
            panel.setBackground(Color.WHITE);
            f.setResizable(false);
            f.setVisible(true);
    }

    First_knight wrote:
    please tell me am i thinking right
    about this method: setImageableArea(.....)
    public void setImageableArea(double x, double y,  double width, double height);
    like I said, I've tried this method and it doesn't seem to do anything.
    the width=the JFrame Width,the height=the JFrame Height right?actually, when printing, 72 points (printing version of pixels) = 1 inch, so to do WYSIWYG, you need width = JFrameWidth * 72.0 / Toolkit.getToolkit().getScreenResolution. Ditto with height
    upper left beginningx(0)---------------------------200--------------------------------600-----------------------------------y(1000)upper right beginningyou need to do something like PageSetup.getImageableX and do Graphics.translate(x,y);
    also, if your page width = 720, that = 10 inches - that's a wide page (unless its in landscape)
    so if i want the JFrame To Be In The Center Of The Page I Would Choose From x=200 ,y=600 depending that frame width is 400Actually, it would be 300 - 700 in your example
    Because when i tried to use:setImageableArea(200, 600,  400, 200);like the above code
    no changes occurs in the printed paperYes. You need to offset the Graphics object

  • How can i Print (with the printer) a JFrame by clicking a button?

    i have a jframe with image and lables on it...
    how can i send it to print by clicking the mouse i mean what to write at the ActionListener?
    Thanks!

    What to search? What do you mean "what to search". I suggested you search the forum using "printerjob" as the keyword.
    Or search the forum using "printing". Think up you own keywords. Read some postings and get some ideas. All the information is in the forum if you look hard enough to find it.

  • Is it Possible to print a JFrame using a printer???

    Hi,
    I've created a JFrame where data is extracted from a database and displayed. I would like to add a button so that I can print the page! I was wondering how would I go about this? ( would i have to write a seperate class and call it, or do i add code in the class i want to print??)
    I am not sure on how to go about printing the page, hope you can help.
    Kind Regards
    RSH

    where can I find the code for this, and how would i go about coding my class to print??
    RSH

  • Print option:-  to print the entire JFrame and its components

    I have created a screen using JFrame.
    The screen contains components such as a graph, combobox, tabbedpane and JTable.
    Now we have given 2 options to the end user, either to print the entire screen(JFrame) or
    the contents available in the table.
    My query is , how can i print the entire screen(all the components must be printed),
    is there any api available for this purpose.
    If possible provide me some sample codes.

    <h3>{color:#ff0000}Cross posted{color}</h3>
    [http://forum.java.sun.com/thread.jspa?threadID=5286030]
    Cross posting is rude.
    db

  • To print a offscreen JFrame

    Hi!
    I have a offscreen JFrame with different panels. I want to print this JFrame, but it seems that it is only possible when the JFrame is visible.
    I have searched through the Forums and found a lot answers about how to manage offscreen images, but in this case its a JFrame what I need to be printed.
    Thanks in advance!
    F�lix

    Thanks KPSeal!
    I tried with your code, but I get the same problem, only if the frame inside the JFramePrintable is visible, the content of the original frame is painted. If the frame is not visible, nothing (that's to say, a white page) is printed.
    Maybe the problem is the way I call the frame to be printed.
    Here send you a snippet with my code:
      private boolean applyChanges(){
          //Print the offscreen frame
            JFrame mjf=new JFrame();
            MyClassWithInfo info=new MyClassWithInfo();//That's what I want to be displayed (a JPanel with information)
            mjf.setBounds(0,0,190,140);
            mjf.getContentPane().setLayout(new BorderLayout());
            mjf.getContentPane().add(info,BorderLayout.CENTER);
            JFramePrintable jfp=new JFramePrintable(mjf);
    //        jfp.frame.setVisible(true); //only when this line is active, I get something....
            PrinterJob pj = PrinterJob.getPrinterJob();
            PageFormat pageFormat = pj.defaultPage();
            try {
                pageFormat.setOrientation(java.awt.print.PageFormat.LANDSCAPE);
                //A new paper object with our settings is created
                Paper paper=new Paper();
                paper.setImageableArea(10,10,545,820);
                paper.setSize(595,841);
                pageFormat.setPaper(paper);
            } catch (Exception ex) { }
            pj.setPrintable(jfp,pageFormat);
            if (pj.printDialog()) {
                try {
                    pj.print();
                catch (Exception p) {
            else{
              return false;
        return true;
      }

  • Printing a JFrame -- it doesn't fit in one page

    Hi, All:
    I like to print out a JFrame to a page. But the JFrame is too big to fit o a page. Does anyone know how to shrink it down and it would fit in a page? The PageFormat I am using is landscape.
    Any help is appreciated!
    Tiny

    Hi TinyBone,
    I am not responding to your current question. I am actually experiencing a problem you had some time ago. You didn't get any responses....but I'm wondering if you ever figured it out. I am getting a -2 when using executeBatch just like you did and can't figure-out why or how to fix it. Would you mind emailing me at [email protected] and tell me whether you ever solved this or not? If so, how?
    Thanks,
    hercules1000
    Hi, your help is greatly appreciated.
    My problem is:
    executeBatch() is returning a array of -2, according to the api,
    commands executed successfully, but the rows affected are
    unknow. Is there any way to fix this so executeBatch() will
    return the correct number?
    Thanks,
    TinyBone

  • Printing a focused chart contained in a JFrame

    Hello everyone,
    I have problem of printing a focused chart which contained in a JFrame. Here is the case:
    1) A JFrame I designed as the root of my application, in which there are menu items, such as Print, Save,Open....
    2)A graphwindow is opened when user hits the "Open" from the above menu list. This graphwindow is basically another JFrame, which contains a chart ( a JPanel). It is an instance of a General chart class somewhere else.
    3) User is able to open multiple graphwindow by selecting different data. the window is able to be focused by a mouse click,just like all the windows applicaiton.
    Hope you have a clear picture now.
    Now, I'm trying to implement the Print function in the Root Frame which should be able to print out the focused the graphwindow. Could anyone please tell me how to do it? any ideas?
    All the reply will be appreciated.
    -SQ

    Here's one thread with my solution:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=501660
    and here's some more discussion:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=407727

Maybe you are looking for

  • Purchase request not created

    Hi , When i am doing MRP run, purchase request are not created.

  • Problems with starting PS6 extended

    I'm getting error 1 on starting up a registered Ps6 extended version.   I'm using win7 64 home premium. The programm worked fine the last days but suddenly this error come up when starting. The standrad trick ctrl-alt-start during start up didn't wor

  • Thumbnails in Sequence... Can they be changed?

    I understand that the thumbnail display for each clip used in the timeline is chosen depending on the "in" mark, in the original clip. Is there a way to change that thumbnail pic based on another mark of some sort? I want the clip to start in the sam

  • BI Publisher is not showing Oracle BI Answers

    Hi, I've OBIEE 10g running on linux. I'm trying to publish one of the reports developed in OBIEE by using BI Publisher. In 'Data Model' -> 'New Data Set' when I use 'Type' as 'Oracel BI Answers' and then click on the 'flashlight' icon next to 'Oracle

  • Storing data

    Hi all Im designing a program to help with booking guets into a small hotel, When a persons details are entered, what would be the best way to store each customers details. Im quite new to java so if what i suggest is a bad idea then please guide me