How to use the relative path of the picture to change the Java WinForm window icon

Source: Internet
Author: User
Tags relative

Today began to contact the development of Javawinform, before the boss has built a simple framework out, let me update from SVN above a familiar, so I went.

Very familiar, very kind of interface style, WINFORM, can meet you here again, is really "ape excrement" ah. This reunion reminds me of the past, in freshman and sophomore time, at that time did in the course design time has done VB and C # WinForm development, as we all know, Microsoft fool-type IDE Let us have fun, so also make WinForm left a beautiful memories, oh, so, I started the quest for Java swing with confidence.

The first is the software login interface, I opened Login.java a look, the eldest brother simply dragged the two label and input, then add two buttons to achieve a login method, which, for a commitment to provide users with a superior user experience of the front-end, it must be unacceptable, so I immediately began the page of the trimming trip.

First of all, I ran a bit, the first found the problem is the window title on the left side of the Java logo is very dazzling, the cup of steaming coffee as a form of the icon looks very unprofessional, a bit of a nondescript feeling, so, I first then take it surgery: first change it!

How do you change it? Unfamiliar with the IDE, unfamiliar fields, this time also do not know how to do, but according to the truth, this should be in the property page can be configured just right, so then use the mouse to click the Login box panel, after all, to let the IDE clear your operational objectives, and then check its property page, There is no such thing as an approximate attribute in the assumption. Well, maybe you haven't chosen the topmost element, so I try to point to the border of the form and find that the right property page shows the currently selected control is JFrame, well, it should be. Again sweep its properties, found that there are two properties are more suspicious, iconimage and Iconimages, according to the meaning of words, probably they can achieve my purpose. Click on the Edit button to the right of the two properties. Pop-up to a corresponding edit box, edited text box is also trapped in a call seticonimage method inside, very naturally, I will originally intended as the icon of the picture URL filled in, and then save, run, no effect, where the problem? Attention to the details, and then check the page, found under the Property editor box, labeled Java.awt.image, I boldly speculate that this parameter must be a Java.awt.image instance, what is the construction method of this example? Can actually through the search API can get, but, I am lazy, directly online check, Seems to have a netizen said direct new a java.awt.IconImage, parameters with a picture of the URL on it, well, this seems to be a bit of a reliable, so, immediately hands-on try it, or the cup of hot coffee, and checked again, seemingly this iconimage also does not meet the requirements, people ask is AW Examples of T.image Oh, is there a problem with this method? So, continue to surf the internet,

Long Quest, finally succeeded, the following methods:

Java.awt.Toolkit.getDefaultToolkit (). GetImage (GetClass (). GetResource ("Images/logo.png")), the parameter required by the GetImage method is an absolute path , but a bit-minded developer should know that absolute paths are risky and inflexible, so use the GetClass (). GetResource method to transition, so that you can implement a relative path to define the form's icon.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.