How do you make java components paint to an image?

I tried having a JPanel as one of my instance variables inside my class.
In the paint method i called paint on the JPanel and passed in a graphics2D object created from an image.
But JPanel does not paint on my image. How do I make it do that?
Basically I want to do some effects on text, but do not want to be bothered about text layout. So I want my JLabel to paint its output on an image and then I can do the effects with the image.
Thanks,

Create an image, get it graphics and call the paint method of the label.
Graphics g = image.getGraphics();
label.paint(g);
The label must be added to a container and visible.

Similar Messages

  • How do you make java self execute?

    Taking a course in java and all of the programs have to be started from the command window by typing java NameOfProgram.
    I am to the point where we are usingparts of the Java API so we have JPanel, JTextField ect. The programs look nice and cool but..,how do I get the program to load from an icon in Windows instead of from the command line in the command window.?

    checked the tutorial stuff and now understand why
    it's not in any of my books. Makes no sense at all
    at this stage. I can't believe that you guys really
    think Java is simple.Well, "simple" needs a bit of qualification.
    As a language, it's less complex than, say, C++, to be sure.
    But "Java" as a general term encompasses a lot. There's the language, which is relatively simple as general-purpose programming languages go (though getting more complex with each release). There's the core API, which includes somewhere around 6500 classes. Then there's the JVM and DLLs that go with it to form the runtime environment. Then there's how you package and deploy a Java program--it could be as an applet, a standalone app as a bunch of classes, a standalone app as a jar file, a web application, a web service, etc. ...
    I don't think creating an executable jar is that complex. It's basically just a zip file with a specific structure and a couple of extra files. But if you're just getting started, I could see why it might seem so. If there are certain particular pieces that are giving you trouble, then feel free to ask. If you're just completley baffled about the whole concept, then, yeah, maybe getting more comfortable with some of the fundamentals first would be better.
    It just seems that there aught to be an easy way to
    do this instead of a major operation.I guess it depends on what you consider "easy" and what "major operation" you're speaking of. I imagine most IDEs (Eclipse, IntelliJ, JBuilder, etc.) will provide a wizard for building an executable jar out of your classes, though I generally recommend that beginners stay away from IDEs, as it can be almost as daunting to learn the IDE as to learn Java for a newcomer, and difficult to tell where the boundary between the two lies.
    Good luck.

  • How do you make a rectangle resize with background image?

    I'm trying to add links (transparent rectangles) to a background image that is set with "scale to fit". However when it scales in needs to scale with my links. Can I have the rectangles scale with the background image? If not is there a better way of doing this?

    As I understand. correctly.  You want the rectangles that you have added over background image, (to which links are added) to be responsive in layout within the project, Am I correct ? If yes ! Muse does not implement "Responsive Layout" as defined by a hand coder. For more details refer to : Can you create responsive sites with Adobe Muse?

  • Newbie Question...  How do you make sure java can find all the imports

    Hi everyone,
    I am new to Java and so far I really like it. But I am having problems porting applets to my websites. How can you make sure that all the references can and will be found in the applet...
    for example,
    I import javax.media.ControllListener in a project I am using and it works great in the applet viewer but when I try to port this to my website I'm working on, java can't find it. I really would appreciate any help on this cause then I would have java power :) and will keep me from losing my hair :).
    Thanks for those who help me.
    - Stan

    Hey jwenting,
    Thanks for the quick response. Classpath definitely makes sense so I have been reading up on that... But do you include .classpath file in your website too? And how would you reference it if you need to reference it?
    - Stan

  • How do you make an array of image icons and then call them?

    How do you make an array of image icons and then call them, i have searched all over the internet for making an array of icons, but i have
    found nothing. Below is my attempt at making an array of icons, but i cant seem to make it work. Basically, i want the image to match the value of the roll of the dice (rollVal)
    Any help would be greatly appreciated, some code or link to tuturial, ect.
    /** DiceRoller.java
    * Roll, print, Gui
    import javax.swing.*;
    public class DiceRoller extends JFrame
         private ImageIcon[] image  ;
         public String[] images = { "empty", "dice1.jpg",
                   "dice2.jpg", "dice3.jpg", "dice4.jpg",
                   "dice5.jpg", "dice6.jpg" };
         public Dice die;
         private int rollVal;
         public int rollNum;
         private JLabel j1;
         public DiceRoller(){
              j1= new JLabel("");
           die =new Dice();
           int rollVal;
           rollVal = die.roll();     
           image = new  ImageIcon[images.length];
         for(int i = 0; i < images.length; i++){
          image[i] = new ImageIcon(images);
         if (image!=null){
              j1.setIcon(image[rollVal]);
         System.out.println("Roll = "+die.roll());

    Demo:
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class IconExample {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch();
        static void launch() {
            try {
                Icon[] icons = new Icon[6];
                for(int i=0; i<icons.length; ++i) {
                    String url = "http://www.eureka-puzzle.be/cast/images/dice" + (i + 1) + ".jpg";
                    icons[i] = new ImageIcon(new URL(url));
                display(icons);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
        static void display(Icon[] icons) {
            JPanel cp = new JPanel();
            for(Icon icon : icons) {
                cp.add(new JLabel(icon));
            JFrame f = new JFrame();
            f.setContentPane(cp);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • How would you make an effect like this?

    Hi! I'm new to the forums, but hopefully it's ok if I start this new discussion. I'm very new to Photoshop as well (newbie).
    Here is the image: http://sffbookreview.files.wordpress.com/2012/10/life-of-pi-banner.png
    How would you make the image on the right - with the watercolor painting crop effect of the tiger? Also, how would you make the font on the left gradually turn to orange?
    Thanks! Your help is much appreciated.

    Hi there,
    Here's a really quick tutorial on how to add the mask and gradient text over the image of a tiger.
    Masking the Image
    1) Open your image of the tiger. There should be two layers in your layers panel: the image and a white background.
    2) With the tiger layer selected, click on the icon marked below in the layers panel to create a layer mask.
    3) Being sure you have the mask you just created selected, paint with black using the brush tool to mask out the image. In your layers panel, if you look at the mask icon, you will see the areas where you were painting (on the canvas) change to black. Use a variety of brushes to recreate the effect in your example image.
    Creating Text with a Gradient Effect
    1) Use the Type Tool to create your basic text and reposition it on the page with the Move Tool.
    2) In the layers panel, control click on the type layer and select Blending Options.
    3) In the dialog box that opens, check the Gradient Overlay box and click on the "gradient overlay" text to move to the gradient options. Adjust the angle of the gradient, then click on the colored bar to select the colors you want. Click OK on each dialog to close them.
    Final result:
    I hope this helps, and please let me know if you need any more assistance.

  • How do you make a web browser?

    I would like to make a Web Browser of my own but how did you make FireFox?

    Read this:
    http://thepattysite.com/window_sizes1.cfm
    You don't want to try to launch your site to full screen,
    honest, as you'd
    drive your (potential) visitors away.
    Jo
    "Steve Zavodny" <[email protected]> wrote in
    message
    news:escrfa$s7$[email protected]..
    > How do you make a web browser launch your site to a
    specific size or even
    > full screen?
    > Thanks...

  • How do you make superscripts and mathematics in Preview's text annotation?

    When adding text annotations that include scientific notations, how do you make superscripts, e.g. "3.2 × 10^{-23}"?
    Searching Help for 'superscript' turns up nothing, suggesting the command does not exist, as it does under Baseline etc. in iWork. Please tell me this is not the case! If it is, has the situation been improved in the new operating system?
    A related issue: I wish to include other mathematics -- is there a way to include mathematics similar to LaTeX? Might Preview incorporate using latex code in the future, so I can easily type "\exp{-\lambda t}" etc and have the math appear?
    I'm adding text annotations to PDF lecture notes in Preview, basically filling in blanks the instructor has left so students will pay attention in class, and these annotations include superscripts; I wish to format properly.
    Thank you!

    Once you have the circle shape displayed, long press on the border of the circle. Once it is highlighted, drag horizontally or vertically. This should allow you to distort the circle into an ellipse (or the square into a rectangle).
    Hope that helps,
    Frank
    Sketch Engineering

  • How can you make one button preform different actions in Xcode?

    How can you make one button "preform a click" and "orderfront"? Is that possible? Because what I am doing is making a welcome window to my application for Mac OS X 10.6, and I have two buttons in that window, one says "Connect" which connects a a WebView to a url and the other button opens up the main window. So how can I a make a button do multiple things at once??

    Ah - If you are just using bindings between various objects from Interface Builder, you can reduce your application code a bit (sometimes quite a bit), but there is only so far you can go. Typically variables and routines are defined in your application that Interface Builder hooks into, so that your application code (usually Objective-C, but can be others) can use these variables and routines to determine what is happening in the user interface.
    I'm not sure how up-to-date the project code is (or what programming code you are familiar with), but you can take a look at Apple's Cocoa Application Tutorial to see what is (usually) involved in creating an application.

  • How can you make the iPod tell the diff between a movie and music video

    Greetings!
    How can you make iPod tell the difference between a Music Video and Movie? Everything I put up on the iPod falls into Movie. So is it something I have to do in iTunes?
    Thanks for the help!

    Rightclick the video in iTUnes, hit Get info then the "Options" tab. Beside kind you can set it to movie. music video. or TV show

  • How do you make the sentences you input in a drop down list wrap to the next line?

    How do you make the sentences that you input in a drop down list to wrap to the next line?

    You can't.
    see this thread for more info:  Can you set drop down list as multi-line???

  • HT204053 I have multiple devices used by family members, how do you make sure the kids don't see Moms messages from Dad and visa versa?

    I have multiple devices used by family members, how do you make sure the kids don't see Moms messages from Dad and visa versa?

    Hi Roger:
    Thanks for the reply.  I think I figured out the problem.  Apple has confused (at least in my mind) the different IDs that people can have.  In the iCloud settings, they use the term Apple ID and not iCloud ID.  I guess there really is no such thing as an iCloud ID.  There are Apple IDs with various attributes.  This is not clearly explained or easy to see (how could I look up to see if my Apple ID is associated with iTunes for example?).
    I created, what I thought were iCloud IDs for each family member, but we all use my Apple ID for iTunes.
    One other question - why does the syncing of Notes using iCloud require an @me.com email account.  That makes no sense to me.
    Thanks for your help!
    AO

  • How do you make a 3d octagon in photoshop cs4 extended?

    How do you make a 3d octagon in photoshop cs4 extended that you can map artwork to? I've been searched online for a solution that doesn't involve using a 3D program but can't find anything. Can't you extrude a shape like in Illustrator, or exporta true 3D shape from Illustrator that will work? I'd use Illustrator but the mapping thing is finicky, and doesn't alow wrapping images around angles. (now someones going to say: "Don't mention any other programs in a PHotoshop forum!" Yeah yeah, there should be a forum then about using different Adobe programs together.) End of rant, any suggestions much appreciated.
    Thanks,
    Mike

    Thanks for your prompt response!
    Suggested Bridge Update
    It turns out that I got a message that this update had already been installed, which led me to more carefully look at the Bridge window and (finally) see that the Output module had a Quality dropdown: Full, 300 ppi, 150 ppi, 96 ppi and 72 ppi.  Thanks!  I decided to compare the CS4/Bridge results to those I got in CS2 with its convenient File/Automate/PDF Presentation/Multi-Page Document routine that I like.
    My project was an 8-page PDF made from scanned pages of handwritten notes into which some fairly small type had been insert using the Photoshop CS2 Type tool.  In Photoshop CS2, I had settled on "medium quality" JPEG compression as giving a "reasonable" file size (about 7 MB) and "very good/excellent" image quality.  I experimented with making the PDF in Bridge, using all five Quality levels.  See table below.  The Bridge "good minus" file was about the same size as the file produced in CS2, which I judged to be "very good/excellent" and slightly better visually than the 300-ppi, 23.5-MB Bridge file.
    Bridge Quality:
    Full
    300 ppi
    150 ppi
    96 ppi
    72 ppi
    File Size:
    25.2 MB
    23.5 MB
    7.6 MB
    3.2 MB
    2.1 MB
    Subjective Quality:
    Very good
    Very good
    Good minus
    Poor
    Useless
    I appreciate that you may not be all that interested in these observations, but it seems to me that Adobe has done us no favors in the multi-page PDF department in going from CS2 to CS4!
    Install the Old Contact Sheet/Picture Package Plug-Ins
    I had already done this some time ago, in order to get in CS4 the File/Automate/Contact Sheet II feature I liked in CS2.  It does not appear to me that this plug-in has anything to do with make multi-page PDF's.  Perhaps I'm missing something.
    Again, thanks for your response!

  • How do you sync iCloud (contact, calendar, task) to outlook 2011 for Mac? and how do you make seemless sync between iCloud to Outlook 2011 to Blackberry device or an iPad?

    I have three device: Macbook Pro (OSX 10.7.5) for work; an iPad and a Blackberry for mobile. I used mail, iCal, and Address Book combine with mobileme (iCloud) to exchange data such as contact, calendar and task from my Mackbook Pro to my iPad but never to Blackberry. The problem is my boss was asking me to change to Outlook 2011 for Mac because some of the email that I sent from Mail did not appear in my client's Blackberry. So how do you sync iCloud (contact, calendar, task) to Outlook 2011 for Mac? and how do you make seemless sync between iCloud to Outlook 2011 to Blackberry device or an iPad?  
    Best regards,
    W. Sasongko

    More Like This --------------------------------------->

  • How do you make a MacBook Pro talk to an Epson printer?

    MacBook Pro
    OS X 10.6.8
    (Thinking about getting  another MacBook)
    I had an Epson Artisan printer, got an Epson Workforce WF-3640 new in Jan, hardly used because I cannot make it do what I want it to do. Wireless connection is good.
    With the MacBook Pro, the interface with the Epson printers is not what it used to be on the G4: no ColorSync, no 2-sided, no thick paper, none of those kinds of instructions appear on the generic printer control panel. Which by the way, bears NO resemblance to the Epson manual screenshots, and the instructions in the Epson manual are useless.
    How do you make a MacBook Pro talk to an Epson printer? And by the way, I cannot use the scanner either. I have to set up a document to print, then when the printing progress box appears, click on the scanner icon.
    Also
    Printer has 2 compartments. Top compartment #1 for all types paper.
    Bottom compartment #2 for plain paper only.
    I load glossy photo paper in #1, it prints plain paper from #2 even though I entered instructions on the control panel on the printer.

    If you haven't done so already, try resetting the printing system.
    Reset Printing System

Maybe you are looking for

  • Dunning letters by age of recievables....

    Hello SAPIENTS, Please let me know is it possible to do dunning letters by age of recievable. for example if want to dunn the customers whose recievables are due for more than 60 days and which should not include recievables less than 60 days. thanks

  • Pending update in Windows 8.1

    I attempted to install the "optional update" KB2975719 in Windows 8.1 however when the computer restarted the update failed to install and the computer would not boot correctly. After trying a number of solutions including the automatic repair and ot

  • Trouble locating logic's plugins

    Hi, this is really a newbie question to ask..but where in logic do i find the plugins that came with it. is it in the mixer box with the sliders or is it a separate box..i'm looking for deesser and a few things to clean up my vocal tracks.

  • Export class files?

    Hi I have a class file but not the .java file. Is there a way to uncompile the class file so I can rebuild the class?

  • Random Net connection call failed errors

    Hi All, I've built a Flex application which is calling coldfusion CFC through remote objects in order to retrieve data. 2 days ago, I've updated the server with coldfusion 9 and my issue is that I have sometime those kind of error messages : [RPC Fau