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 / General / February 2006

Tip: Looking for answers? Try searching our database.

Grayscale a Jpanel

Thread view: 
Mahesh - 10 Feb 2006 13:34 GMT
Hi,
I have a Jpanel containing Jtext,Jlabel,.... (producing a report),When
I tried to print the Jpanel it is takin too much time to reach a
printer(size 3MB!). I think it will be ok if we get hem grayscaled.
Anyone have an idea to graycale a Jpanel or Jframe? I searched in
Google but no use.
Andrey Kuznetsov - 10 Feb 2006 14:28 GMT
> I have a Jpanel containing Jtext,Jlabel,.... (producing a report),When
> I tried to print the Jpanel it is takin too much time to reach a
> printer(size 3MB!). I think it will be ok if we get hem grayscaled.
> Anyone have an idea to graycale a Jpanel or Jframe? I searched in
> Google but no use.

Component contains special method for printing.
You have to override it.
You can create first BufferedImage (TYPE_BYTE_GRAY) and paint everything to
it.
Then paint this image to Graphics.

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

zero - 10 Feb 2006 16:34 GMT
"Mahesh" <registered.here@gmail.com> wrote in news:1139578453.374852.63230
@z14g2000cwz.googlegroups.com:

> Hi,
> I have a Jpanel containing Jtext,Jlabel,.... (producing a report),When
> I tried to print the Jpanel it is takin too much time to reach a
> printer(size 3MB!). I think it will be ok if we get hem grayscaled.
> Anyone have an idea to graycale a Jpanel or Jframe? I searched in
> Google but no use.

try this:

BufferedImage img = new BufferedImage(jPanel.getWidth(),
  jPanel.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
jPanel.paintComponent(img.getGraphics());
// print img

or:

BufferedImage img = new BufferedImage(jPanel.getWidth(),
  jPanel.getHeight(), BufferedImage.TYPE_INT_RGB);
jPanel.paintComponent(img.getGraphics());
Image grayImage = GrayFilter.createDisabledImage(img);
// print grayImage
Mahesh - 14 Feb 2006 10:42 GMT
This buffered image can be done on the xternal image files
like(jpeg,bmp) which we place inside the panel. But I need the entire
panel to be grayscaled.Consider a panel which is having only
Jcomponets!
zero - 14 Feb 2006 18:22 GMT
"Mahesh" <registered.here@gmail.com> wrote in news:1139913753.091108.215780
@g47g2000cwa.googlegroups.com:

> This buffered image can be done on the xternal image files
> like(jpeg,bmp) which we place inside the panel. But I need the entire
> panel to be grayscaled.Consider a panel which is having only
> Jcomponets!

That's why you use jPanel.paintComponent(bufferedImage.getGraphics());
This paints the jPanel, and everything in it, onto the image's graphics
object.  This is exactly the same as painting it on the screen.


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



©2009 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.