Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2008

Tip: Looking for answers? Try searching our database.

issue with printing using jdic

Thread view: 
anoopgeorgee@gmail.com - 06 Jan 2008 13:31 GMT
Hi,

I have a program which use JDIC webbrowser to display an html page.
the webbrowser.print() has been called to print the page. The page is
displayed properly on the window. But the printing does nopt happen.
No error messages also. Any help will be greatly appreaciated.

plz find the source of my program below:

public HTMLViewer(URL url) {
       this.url=url;
       WebBrowser webBrowser = new WebBrowser();
       webBrowser.setSize(1000,700);
       JFrame frame = new JFrame("My Report");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       JMenuBar menuBar;
       JButton print=new JButton("Print");
       menuBar = new JMenuBar();
       menuBar.add(print);
       frame.setJMenuBar(menuBar);

       Container contentPane = frame.getContentPane();
       contentPane.add(webBrowser, BorderLayout.CENTER);
       frame.pack();
       frame.setVisible(true);

       webBrowser.setURL(url);
       PrintButtonListener p= new PrintButtonListener(webBrowser);
       print.addMouseListener(p);

   }

//main method:

   public static void main(args[]){
       HTMLViewer h= new HTMLViewer();
   }

//inner class:

   class PrintButtonListener  extends  MouseAdapter{
       WebBrowser webBrowser=new WebBrowser();

       public PrintButtonListener(WebBrowser webBrowser){
           this.webBrowser=webBrowser;
       }
       public void mouseClicked(java.awt.event.MouseEvent evt) {
           webBrowser.print(webBrowser.getGraphics());
       }
   }
PM2K - 06 Jan 2008 21:01 GMT
Read JavaDoc 4 webBrowser.print carefully:
----------------------------------------------
Prints this component. Applications should override this method for
components that must do special processing before being printed or
should be printed differently than they are painted.

The default implementation of this method calls the paint method.

The origin of the graphics context, its (0, 0) coordinate point, is
the top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.

See Also:
paint(Graphics)
-----------------------------------------------
The most important is this sentence:
The default implementation of this method calls the paint method.
This method isn't 4 printing to printer. Try another way, 4 example:

    class PrintButtonListener  extends  MouseAdapter {
       WebBrowser webBrowser=new WebBrowser();

       public PrintButtonListener(WebBrowser webBrowser){
           this.webBrowser=webBrowser;
       }
       public void mouseClicked(java.awt.event.MouseEvent evt) {
           webBrowser.executeScript("window.print();");
       }
    }

Enjoy!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.