com.sun.awt package usage

17,430

Solution 1

JNA is an additional library and not part of the standard api, you have to download it (here) and include it in your classpath.

The AWTUtilities class is only distributed with the sun jvm as an implementation detail of the api and as such subject to change, this can break any program depending on it (if possible don't use it).

WindowUtils can be found in the platform.jar, you it can find it on the same page as jna.

Solution 2

Your JDK should have com.sun.awt.AWTUtilities. It is in rt.jar.

Maybe the problem (for that file) is that your IDE excludes the parent the build path ... on the grounds that it is a bad idea to use those classes directly.

The com.sun.jna classes are not in rt.jar. They apparently may be found in a jna.jar, though I haven't yet found a good place to download it from. (If you use Maven, try this.)

Solution 3

You should not use any com.sun packages except as a last resort. These are considered to be implementation details, and they are not part of the JDK API. They can change arbitrarily between versions, so they can cause problems when you try to upgrade JDK versions.

The com.sun classes are almost always wrapped by "official" classes - you should use those instead. You can use these in a last resort situation, but they are already part of the JDK download, so there should be no extra downloading necessary.

EDIT: Looks like you're right, you do need to download some extra jars. The JNA jar is available on maven central (http://mvnrepository.com/artifact/com.sun.jna/jna/3.0.9). Especially if this is a code snippet you found, I would highly advise against using com.sun packages directly.

Share:
17,430

Related videos on Youtube

sajad
Author by

sajad

Updated on May 05, 2022

Comments

  • sajad
    sajad about 2 years

    I found a java code and want to use it in my project. It contains these imports that my JDK does not have :

    import com.sun.awt.AWTUtilities;
    import com.sun.jna.Native;
    import com.sun.jna.platform.WindowUtils;
    

    I referred to sun site and found this download page :

    http://www.oracle.com/technetwork/java/javase/downloads/index.html

    Is it necessary to download all JDK and JRE and replace it from SUN website? My JDK is version 6 and is up to date.

    Thank you all

  • sajad
    sajad over 13 years
    thank you. yes about com.sun.AWTUtilities. But import com.sun.jna.Native; com.sun.jna.platform.WindowUtils; Are still my problem. I think I have to add external library to my project.
  • sajad
    sajad over 13 years
    thank you. yes about com.sun.AWTUtilities. But import com.sun.jna.Native; com.sun.jna.platform.WindowUtils; Are still my problem. I think I have to add external library to my project.
  • sajad
    sajad over 13 years
    Yes jna 3.0.9 has com.sun.jna.Native; But what about com.sun.jna.platform.WindowUtils ?? This class has a method : WindowUtils.getAlphaCompatibleGraphicsConfiguration() that returns a GraphiConfigurations Object that is used in my code. I also want to run my code in linux. so this is important to me. Is this the last version of jna ? Thank you.
  • sajad
    sajad over 13 years
    Thank you. But do you know how I can find a jar file that contains : com.sun.jna.platform.WindowUtils ? This is important to me because I also want to run my code on linux.
  • Débora
    Débora almost 12 years
    @StephenC. I had the same problem. my jre was default 1.6 only in my IDE. I spent so long time to solve it,but I couldn't. fortunately I found your answer. Your advice 100% helped me and perfectly worked for me. Your are geniuse, superb perfect man. All merits to you. Thank you sooooooooooo much. If i could, I upvote u 10000times.