Solved

Creating an Image of a invisible component

Posted on 2003-11-04
9
190 Views
Last Modified: 2010-03-31
Hi, i know how to create a Image from a JComponent or anything that have a paint function. It create my Image with no problem. But now i have to create a Image Object of a JComponent that the user won't have to see. I set my Component to setVisible(false) and when i create the Image, my Image Object is null but if i setVisible(true) and i do the Image it's ok. So my question: "is there a way to create an Image Object from a Component that are not visible?"

i use this code to create the Image Object


Rectangle rect = table.getBounds();
Image ima = createImage(rect.width, rect.height);
Graphics2D g = (Graphics2D) ima.getGraphics();
table.paint(g);
g.dispose();



thx
0
Comment
Question by:bumpert
  • 5
  • 3
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9680287
You could only save an image of something when it's visible, so you'd have to show it then hide it.
0
 

Author Comment

by:bumpert
ID: 9680329
hummm it's not really usefull.... cause i do my picture when a bi things is loading, so the user have the time to see the component visible, and i cant do my image elsewhere...

i was thinking that somebody could have a solution for that :(

thx
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9680481
AFAIK, that's the situation i'm afraid
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:bumpert
ID: 9681393
humm ok
0
 

Accepted Solution

by:
vitallis earned 125 total points
ID: 9707900
I had the same task and the solution was very simple. What I did is
- created offscreen buffered image
    int width = <desired width>;
    int height = <desired height>;
    java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(width, height, java.awt.image.TYPE_INT_ARGB);
- created Graphics2D of it
    java.awt.Graphics2D gr = ni.createGraphics();
- called the component paint()
    table.paint(gr);

Now I have an offscreen image.
0
 

Author Comment

by:bumpert
ID: 9708049
thx someone already answer me on the java forum, but i'll give you the points
0
 

Author Comment

by:bumpert
ID: 9708053
java sun forum, sorry :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9709695
Sorry bumpert - for some reason, an off-screen image didn't occur to me.
0
 

Author Comment

by:bumpert
ID: 9714587
no problem man, we cannot know all the things :)
if yes i didn't post qa question here :)

thx to all for your help
im leaving this topic
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 32
table example 4 32
MySQL  on Tomcat 8 68
hibernate insert example 13 34
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question