How to use Toolkit.getDefaultToolkit().getImage in JPanel in Java Swing

Hi Sir,
I want to know how to use Toolkit.getDefaultToolkit.getImage()
in JPanel (ie) the class that extends the JPanel.There is no problem to include the Toolkit.getDefaultToolkit.getImage()in JFrame.It is displaying it without any problem.But in JPanel it is showing a problem of cannot resolve symbol.Here i can't use JFrame instead of
JPanel.So how to solve the problem.Pls.do send the code of how to do this.It is Urgent.
Thanx,
M.Ananthu

you use Toolkit.getDefaultToolkit.getImage() in a JPanel exactly the same way you do in a JFrame.
You are getting a compile message "cannot resolve symbol". You have made a programming error and since you have not included code there is no way to guess what you did wrong.

Similar Messages

  • Always return "Image Object" in Toolkit.getDefaultToolkit().getImage();

    A : Image source = Toolkit.getDefaultToolkit().getImage("C:/aa.jpg");
    B : Image source = Toolkit.getDefaultToolkit().getImage("");
    generally, B may be null. but it is not null.
    so I look at "javax.swing.ImageIcon" class :
    <Part of ImageIcon source>
    public ImageIcon(String filename, String description) {
         image = Toolkit.getDefaultToolkit().getImage(filename);
    if (image == null) { //This code is invaild.
    return; //never return.
         this.filename = filename;
    this.description = description;
         loadImage(image);
    Do you thinking it?
    Bug?

    getimage may not return null in the current implementation but they wanted maybe get sure that no nullpointerexception occures.
    it's not a bug - it's a feature :-)

  • How can i put one scene into JPanel of the swing?

    how can i put one scene into JPanel of the swing?

    980571 wrote:
    ty for the information but i have a problen with JFXpanel when i try to into a panel it doesnt display insideSorry to hear that. If you want assistance with the code, feel free to post the relevant parts of it. Make sure to use \ tags when you do.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use line wrapping and line spacing in java?how to use line wrapping

    how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?how to use line wrapping and line spacing in java?

    Hello,
    You should post your question at:
    http://java.forum.sun.com
    Thanks
    - Rose

  • How to use line wrapping and line spacing in java?

    how to use line wrapping and line spacing in java?

    Hi,
    This is explained in the java Tutorial. Please see the link:
    http://java.sun.com/docs/books/tutorial/i18n/text/line.html
    and find some sample examples.
    Hope this helps,
    --Sun/DTS                                                                                                                                                                                                                                                                                                                                                                                       

  • How to use Toolkit.prepareImage()??

    hey,
    I was wondering how to use the prepareImage() method in the Toolkit class. So far i've been using the method just before I paint an image to the screen. Is there any better usage for it. Is my way slowing the painting proccess down?
    here's some sample code
    Image image;
    Toolkit tk;
    public void paint(Graphics g){
            tk.prepareImage(image, 32, 32);
            g.drawImage(image, 0, 0, this);
    }Thanks,
    Bluelikeu

    Do you really want to load the images asynchronously or are you willing to wait?
    If you can wait, javax.imageio.ImageIO is a simpler way to load images.
    And even if you load in a seperate thread, you can do it with ImageIO:
    import java.awt.*;
    import java.io.*;
    import java.net.URL;
    import javax.imageio.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class BackgroundBorderExample {
        public static void main(String[] args) throws IOException {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame f = new JFrame("BackgroundBorderExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextArea area = new JTextArea(24,80);
            area.setForeground(Color.WHITE);
            area.setOpaque(false);
            area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
            final JScrollPane sp = new JScrollPane(area);
            sp.setBackground(Color.BLACK);
            sp.getViewport().setOpaque(false);
            f.getContentPane().add(sp);
            f.setSize(600,400);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            String url = "http://today.java.net/jag/bio/JagHeadshot.jpg";
            final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
            Runnable r = new Runnable() {
                public void run() {
                    sp.setViewportBorder(bkgrnd);
                    sp.repaint();
            SwingUtilities.invokeLater(r);
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.border.*;
    public class CentredBackgroundBorder implements Border {
        private final BufferedImage image;
        public CentredBackgroundBorder(BufferedImage image) {
            this.image = image;
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            int x0 = x + (width-image.getWidth())/2;
            int y0 = y + (height-image.getHeight())/2;
            g. drawImage(image, x0, y0, null);
        public Insets getBorderInsets(Component c) {
            return new Insets(0,0,0,0);
        public boolean isBorderOpaque() {
            return true;
    }Warning: explicit image!

  • How to use MICR fonts in Adobe forms (webdynpro java

    Hi,
          We have a requirement where we need to print some MICR codes (for checks) through Adobe Forms.
    I have installed some true type MICR fonts in windows and Adobe Font Manager (in ADS) as well.
    It is visible in the Adobe Form design time (Font palette) and when I use the font for text, it is visible in preview too. But when I run the web dynpro application, in the online form it is converted into Standard font (Times new Roman).
    Is there anyway to handle this issue.
    Please let me know.
    I am using NWDS 7.0.1
    Adobe Live cycle designer 7.1
    SAP NW 2004s SP14
    Thank you,
    Vasu

    Check this forum post (though that is for 6i, it would be of helpful for you)
    How to use unicode fonts in Oracle forms 10g?
    -Arun

  • How to use SQl server 2005's SQLXMLBulkLoad with JAVA

    Hi All,
    I am in a big problem identifying how to use xml bulk insert functionality of sql server 2005 with java.
    I need to enter millions of data into the sql server 2005 database.
    All the material i saw on net includes vb script or asp.net sripts to do so.
    Somebody please tell how I can do this with JAVA.
    Thanks.

    In this forum we commonly discuss connections from Oracle to foreign databases. When you want to connect with your SQL Server to Oracle it would be better to ask that in a Microsoft forum as they support their LINKED SERVER mechanism.
    The linked server set up is for example described in the Microsoft knowledge base as:
    280106 - HOW TO: Set Up and Troubleshoot a Linked Server to Oracle in SQL Server
    In newer SQl Server releases the name changed see for example:
    How to run a SQL Server 2005 Integration Services package as a SQL Server Agent job step
    View products that this article applies to.
    Article ID : 912911
    As you can see they are commonly using OLEDB driver. So you might have to install Oracle's OLEDB driver as well. Else you might think about using OLEDB to ODBC bridge

  • How to use Try Catch Block in ABAP Like JAVA

    Hi Experts,
       I am using BAPI to post MIGO in one of my application. If the MIGO is successfully gets posted then BAPI returns no message, but if there is some error in posting then it returns an error message. Now I want to print that error message in catch block by calling method RAISE_ERROR_MESSAGE. How to use try catch block in ABAP. Please suggest with example.
    Thanks and Regards.
    Vaibhav Tiwari.

    Hi Vaibhav
    You may not catch exceptions returned by function module using try endtry block.
    It works well with the exception returned by methods.
    In case of function modules or BAPI what u can do is to check sy-subrc returned and give message accordingly. If it returns a structure like bapireturn then display message returned.
    in case of exception returned by a method,  do it like this...
    data: excep type cx_root.
    data: v_str type string.
    try.
    *any method call or division by zero (for ex)
    catch cx_root into excep.
    endtry.
    if  excep is not initial.
    CALL METHOD   excep->if_message~get_text
      receiving
        RESULT = v_str.
    endif.
    *display the value returned in v_str on screen

  • How to use the One-to-One mapping in Java Code

    Dear all:
    I have set the direct mapping and named query,
    and have written web service of login.
    I can login successfully.
    Now,I want learning about One-to-One mapping.
    I have setting the One-to-One mapping,
    then what can I do latter?
    I do not found any paper showing how to use it in web service?
    Somebody help me?thx all.

    Following code worked for me:
    import oracle.javatools.resourcebundle.BundleFactory;
    import java.util.ResourceBundle;
    * This method retrieves localized strings from a given XLIF resource bundle.
    * @param bundleName The XLIF bundle from which the localized string is to be retrieved.
    * @param key The key of the localized string.
    * @return The localized string retrieved from the given XLIF bundle.
    public static String getXlifLocalizedString(String bundleName, String key) {
    if (StringUtils.isEmpty(key)) {
    return key;
    if (StringUtils.isEmpty(bundleName)) {
    return "[" + key + "]";
    String localizedString = null;
    ResourceBundle resourceBundle = null;
    try {
    resourceBundle = BundleFactory.getBundle(bundleName);
    localizedString = resourceBundle.getString(key);
    } catch (Exception e) {
    LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
    return "[" + key + "]";
    return localizedString;
    }

  • How to use XLIFF file as resource bundle in Java code

    We use xliff as resource bundle for our ADF application. it is has been no problem to have localized message displayed on UI. how ever, I'm wonderring how to use Java code to access xliff as resource bundle which similar to access properties resource bundle. for example:
    Locale myLocale = new Locale("es", "ES");
    ResourceBundle bundle = ResourceBundle.getBundle("HelloResourceBundle", myLocale);
    System.out.println(bundle.getString("Hello"));is it posible to create "HelloResourceBundle" in xliff format?
    Thanks

    Following code worked for me:
    import oracle.javatools.resourcebundle.BundleFactory;
    import java.util.ResourceBundle;
    * This method retrieves localized strings from a given XLIF resource bundle.
    * @param bundleName The XLIF bundle from which the localized string is to be retrieved.
    * @param key The key of the localized string.
    * @return The localized string retrieved from the given XLIF bundle.
    public static String getXlifLocalizedString(String bundleName, String key) {
    if (StringUtils.isEmpty(key)) {
    return key;
    if (StringUtils.isEmpty(bundleName)) {
    return "[" + key + "]";
    String localizedString = null;
    ResourceBundle resourceBundle = null;
    try {
    resourceBundle = BundleFactory.getBundle(bundleName);
    localizedString = resourceBundle.getString(key);
    } catch (Exception e) {
    LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
    return "[" + key + "]";
    return localizedString;
    }

  • How to use chinese big5 fonts in Linux with Java 2 1.4.0.01? Please help me

    Hello
    I just trying to run a java program in Mandrake Linux 8.2. Everythings work well except the fonts. I did read this page
    http://java.sun.com/j2se/1.3/docs/guide/intl/fontprop.html
    but the problem still there.
    Because I don't know how to modify the fonts.properties file. Java seem not support a world language version in Linux. (Although it support in Windows.)
    Then I tired to use the windows file, fonts.properties.xh_TW, to replace the fonts.properties in j2sdk in Linux. But it doesn't work.
    Please help me by either show me how to modify the fonts.properties file or direct me where to download a Big5 fonts in Linux version. Thanks a lot!!!

    Sorry I have been out of for a long time.
    If you already follow all the step of Locale help online,
    may be your font.dir in your /usr/lib/X11/fonts/TrueType/fonts.dir is not as
    the alias it was expected.
    take a look of that file.
    In xtt for chinese, there may be short cut like vl=y as such, because java
    render the font directly getting info from the fonts.dir so if the font filename
    is not as expected, you will not able to load the fonts. What you need to do is
    ln -s realfont vl=y:realfont
    to link the font to the make java think the name of the font is actually vl=y:realfont.
    Let me know you get it.
    [email protected]

  • How to use microsoft speech sdk 5.1 in java application?

    I download the speech sdk 5.1 from microsoft site,and want to use it in my java application,the following are the codes of the application(it uses boot.jar,swt.jar,jface.jar,runtime.jar,swt-win32-3101.dll) ,but gives me the exception,how should i do?it it is not supported by java,what others can i use?
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.SWTException;
    import org.eclipse.swt.internal.ole.win32.TYPEATTR;
    import org.eclipse.swt.ole.win32.OLE;
    import org.eclipse.swt.ole.win32.OleAutomation;
    import org.eclipse.swt.ole.win32.OleControlSite;
    import org.eclipse.swt.ole.win32.OleFrame;
    import org.eclipse.swt.ole.win32.OleFunctionDescription;
    import org.eclipse.swt.ole.win32.OlePropertyDescription;
    import org.eclipse.swt.widgets.Shell;
    public class Main
        public static void main(String[] args)
             args = new String[1];
             args[0] = "Sapi.SpVoice";
            if (args.length == 0)
                System.out.println("Usage: java Main <program id>");
                return;
            String progID = args[0];
            //progID = "word.Document.8";
            Shell shell = new Shell();
            OleFrame frame = new OleFrame(shell, SWT.NONE);
            OleControlSite site = null;
            OleAutomation auto = null;
            try
                site = new OleControlSite(frame, SWT.NONE, progID);
                auto = new OleAutomation(site);
            catch (SWTException ex)
                System.out.println("Unable to open type library for " + progID);
                return;
          TYPEATTR typeattr = auto.getTypeInfoAttributes();
    }it gives me the error:
    org.eclipse.swt.SWTException: Failed to create Ole Client. result = -2147221164
    Unable to open type library for Sapi.SpVoice
    at org.eclipse.swt.ole.win32.OLE.error(OLE.java:302)
    at org.eclipse.swt.ole.win32.OleControlSite.<init>(OleControlSite.java:100)
    Main.main(Main.java:43)

    Hello chengshwu ,
    Have heard of JNI ?
    Please check this.
    http://danadler.com/jacob/

  • How to use class in JSP page ? In java works in JSP not...

    Hello developers,
    I need check if URL exists.. i use this code in java.. it works fine..
    import java.net.*;
    import java.io.*;
    public class Check {
    public static void main(String s[]) {
        System.out.println(exists("http://www.google.com"));
        System.out.println(exists("http://www.thisURLdoesntexis.com"));
    static boolean exists(String URLName){
      try {
        HttpURLConnection.setFollowRedirects(false);
        // note : you may also need
        //        HttpURLConnection.setInstanceFollowRedirects(false)
        HttpURLConnection con =
           (HttpURLConnection) new URL(URLName).openConnection();
        con.setRequestMethod("HEAD");
        return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
      catch (Exception e) {
           e.printStackTrace();
           return false;
    }in java all works fine.. it shows
    TRUE
    FALSE
    but i have no idea how can i implement this java code to my check.jsp page..
    i tried something like this..
    <%@ page import="java.io.*" %>
    <%@ page import ="java.net.*" %>
    <BODY>
    <%
    static boolean exists(String URLName){
      try {
        HttpURLConnection.setFollowRedirects(false);
        // note : you may also need
        //        HttpURLConnection.setInstanceFollowRedirects(false)
        HttpURLConnection con =
           (HttpURLConnection) new URL(URLName).openConnection();
        con.setRequestMethod("HEAD");
        return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
      catch (Exception e) {
           e.printStackTrace();
           return false;
    String a="http://www.google.com";
    %>
    <%= exists(a)%>and i want to see in my jsp page the result.. it means that JSP page shows
    TRUE
    Thanks in advance,

    Hi there,
    One solution is to use JavaBeans and call the methods for the JavaBean from the JSP page.
    Suppose you have a JavaBean called TestConnectionBean as follows:
    package test22;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.IOException;
      Set the testUrl before checking if connection exists.
    public class TestConnectionBean {
        String testUrl;
        boolean connectionExists;
        public TestConnectionBean() {
        public String getTestUrl() {
            return testUrl;
        public void setTestUrl(String testUrl) {
            this.testUrl = testUrl;
        public boolean getConnectionExists() throws IOException, MalformedURLException {
            HttpURLConnection.setFollowRedirects(false);
            // note : you may also need
            //        HttpURLConnection.setInstanceFollowRedirects(false)
            HttpURLConnection con = null;
            con = (HttpURLConnection) new URL(this.testUrl).openConnection();
            con.setRequestMethod("HEAD");
            return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
        public void setConnectionExists(boolean connectionExists) {
            this.connectionExists = connectionExists;
    }Then you can create a JSP page like this:
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
      <head><title></title></head>
      <body>
      <jsp:useBean id="testConnectionBean" class="test22.TestConnectionBean"/>
      <jsp:setProperty name="testConnectionBean" property="testUrl" value="http://www.google.com" />
      <br/><br/>
      Does the connection exist for http://www.google.com : <jsp:getProperty name="testConnectionBean" property="connectionExists"/>
      <br/><br/>
      <jsp:setProperty name="testConnectionBean" property="testUrl" value="http://www.thisURLdoesntexis.com" />
      <br/><br/>
      <%-- The following will give an exception : java.net.UnknownHostException: www.thisURLdoesntexis.com since the URL doesn't exist. 
      --%>
      <%--
      Does the connection exist for http://www.thisURLdoesntexis.com : <jsp:getProperty name="testConnectionBean" property="connectionExists"/>
      --%>
      </body>
    </html>The output you see looks like:
    Does the connection exist for http://www.google.com : true
    I think it is better to handle the exceptions in the JavaBean itself, so now yyou can change the method signature of getConnectionExists , remove all exceptions from method signature but handle them with a try/catch inside the method itself.

  • How to use the google search from inside a java program

    Hi guys
    How can i use google search in my java program?
    What will be the type of the reply i get back from google?
    Thanks in advance
    [http://javamilestone.blogspot.com/|http://javamilestone.blogspot.com/]

    Hi,
    You have here some examples about how to make search on google from a Java application.
    The type of reply is JSON
    Here some documentation about it:
    [http://code.google.com/apis/ajaxsearch/documentation/#fonje|http://code.google.com/apis/ajaxsearch/documentation/#fonje]
    And here some snippets:
    [http://code.google.com/apis/ajaxsearch/documentation/#fonje_snippets|http://code.google.com/apis/ajaxsearch/documentation/#fonje_snippets]
    Regards,
    David.

Maybe you are looking for