Своя иконка программы в java

Class ImageIcon

An implementation of the Icon interface that paints Icons from Images. Images that are created from a URL, filename or byte array are preloaded using MediaTracker to monitor the loaded state of the image.

For further information and examples of using image icons, see How to Use Icons in The Java Tutorial.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder .

Nested Class Summary

Field Summary

Constructor Summary

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Читайте также:  Пример JavaScript

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Method Summary

Methods declared in class java.lang.Object

Field Details

component

Do not use this shared component, which is used to track image loading. It is left for backward compatibility only.

tracker

Do not use this shared media tracker, which is used to load images. It is left for backward compatibility only.

Constructor Details

ImageIcon

Creates an ImageIcon from the specified file. The image will be preloaded by using MediaTracker to monitor the loading state of the image.

ImageIcon

Creates an ImageIcon from the specified file. The image will be preloaded by using MediaTracker to monitor the loading state of the image. The specified String can be a file name or a file path. When specifying a path, use the Internet-standard forward-slash («/») as a separator. (The string is converted to an URL, so the forward-slash works on all systems.) For example, specify:

new ImageIcon("images/myImage.gif")

ImageIcon

Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image.

ImageIcon

Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image. The icon’s description is initialized to be a string representation of the URL.

ImageIcon

ImageIcon

Creates an ImageIcon from an image object. If the image has a «comment» property that is a string, then the string is used as the description of this icon.

ImageIcon

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class.

ImageIcon

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class. If the resulting image has a «comment» property that is a string, then the string is used as the description of this icon.

ImageIcon

Method Details

loadImage

getImageLoadStatus

getImage

setImage

getDescription

Gets the description of the image. This is meant to be a brief textual description of the object. For example, it might be presented to a blind user to give an indication of the purpose of the image. The description may be null.

setDescription

Sets the description of the image. This is meant to be a brief textual description of the object. For example, it might be presented to a blind user to give an indication of the purpose of the image.

paintIcon

Paints the icon. The top-left corner of the icon is drawn at the point ( x , y ) in the coordinate space of the graphics context g . If this icon has no image observer, this method uses the c component as the observer.

getIconWidth

getIconHeight

setImageObserver

Sets the image observer for the image. Set this property if the ImageIcon contains an animated GIF, so the observer is notified to update its display. For example:

icon = new ImageIcon(. ) button.setIcon(icon); icon.setImageObserver(button);

getImageObserver

toString

getAccessibleContext

@BeanProperty(expert=true, description=»The AccessibleContext associated with this ImageIcon.») public AccessibleContext getAccessibleContext ()

Gets the AccessibleContext associated with this ImageIcon. For image icons, the AccessibleContext takes the form of an AccessibleImageIcon. A new AccessibleImageIcon instance is created if necessary.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Class ImageIcon

An implementation of the Icon interface that paints Icons from Images. Images that are created from a URL, filename or byte array are preloaded using MediaTracker to monitor the loaded state of the image.

For further information and examples of using image icons, see How to Use Icons in The Java Tutorial.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder .

Nested Class Summary

Field Summary

Constructor Summary

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Method Summary

Methods declared in class java.lang.Object

Field Details

component

Do not use this shared component, which is used to track image loading. It is left for backward compatibility only.

tracker

Do not use this shared media tracker, which is used to load images. It is left for backward compatibility only.

Constructor Details

ImageIcon

Creates an ImageIcon from the specified file. The image will be preloaded by using MediaTracker to monitor the loading state of the image.

ImageIcon

Creates an ImageIcon from the specified file. The image will be preloaded by using MediaTracker to monitor the loading state of the image. The specified String can be a file name or a file path. When specifying a path, use the Internet-standard forward-slash («/») as a separator. (The string is converted to an URL, so the forward-slash works on all systems.) For example, specify:

new ImageIcon("images/myImage.gif")

ImageIcon

Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image.

ImageIcon

Creates an ImageIcon from the specified URL. The image will be preloaded by using MediaTracker to monitor the loaded state of the image. The icon’s description is initialized to be a string representation of the URL.

ImageIcon

ImageIcon

Creates an ImageIcon from an image object. If the image has a «comment» property that is a string, then the string is used as the description of this icon.

ImageIcon

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class.

ImageIcon

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class. If the resulting image has a «comment» property that is a string, then the string is used as the description of this icon.

ImageIcon

Method Details

loadImage

getImageLoadStatus

getImage

setImage

getDescription

Gets the description of the image. This is meant to be a brief textual description of the object. For example, it might be presented to a blind user to give an indication of the purpose of the image. The description may be null.

setDescription

Sets the description of the image. This is meant to be a brief textual description of the object. For example, it might be presented to a blind user to give an indication of the purpose of the image.

paintIcon

Paints the icon. The top-left corner of the icon is drawn at the point ( x , y ) in the coordinate space of the graphics context g . If this icon has no image observer, this method uses the c component as the observer.

getIconWidth

getIconHeight

setImageObserver

Sets the image observer for the image. Set this property if the ImageIcon contains an animated GIF, so the observer is notified to update its display. For example:

icon = new ImageIcon(. ) button.setIcon(icon); icon.setImageObserver(button);

getImageObserver

toString

getAccessibleContext

@BeanProperty(expert=true, description=»The AccessibleContext associated with this ImageIcon.») public AccessibleContext getAccessibleContext ()

Gets the AccessibleContext associated with this ImageIcon. For image icons, the AccessibleContext takes the form of an AccessibleImageIcon. A new AccessibleImageIcon instance is created if necessary.

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

How to change a frame’s title bar icon (application icon) in Java AWT Toolkit

Carlos Delgado

Learn how to define a custom icon for a frame in the AWT Toolkit of Java.

How to change a frame's title bar icon (application icon) in Java AWT Toolkit

The customization of your application is essential to create a confidence feeling for your user. One of those tiny details is the usage of an icon, to leave at least the impression that you are really working dedicatedly in the application. In this article we’ll show you how you can quickly change the icon of your application with the code in Java AWT Toolkit.

The only thing you will need is an image to use as icon for your application, if you are lacking of imagination or you just want to test quickly, you can download some random icon from this website. Once you have some icon to use, just follow the next logic:

// Create some frame instance Frame window = new Frame(); // Create an image instance from the image that you want to use as icon for your app Image icon = Toolkit.getDefaultToolkit().getImage("C:\\some-directory\\icon.png"); // And set it window.setIconImage(icon);

You will need an instance of a Frame that allows the customization of the icon, then create an instance of an Image with the default Toolkit of Java AWT from a local path (note that if the file is inside your project resources, you can use a relative path or join it with the current application path). The getImage method of the toolkit returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG. Finally call the setIconImage method from the frame and pass as first argument the instantiated image.

Note

The recommended format is the PNG that allows transparency on your icon so it will look better on any screen.

Application context example

The following code represents the mentioned logic during the initialization of a frame within a structured application context:

package sandbox; import java.awt.*; public class Sandbox < Sandbox()< // Create a new frame Frame window = new Frame(); // Create an image instance from the image that you want to use as icon for your app. Image icon = Toolkit.getDefaultToolkit().getImage("C:\\some-directory\\icon.png"); window.setIconImage(icon); // Set other options of the frame . window.setLayout(null); window.setSize(400,400); window.setVisible(true); >/** * Initialize app. * * @param args */ public static void main(String[] args) < Sandbox app = new Sandbox(); >> 

Источник

Оцените статью