Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Multiple image sizes in frame icon (window icon) in Swing

Reply
Thread Tools

Multiple image sizes in frame icon (window icon) in Swing

 
 
Dan Polansky
Guest
Posts: n/a
 
      02-11-2007
Hello, in Swing, how can I achieve that a frame icon has several
images associated with it, in different sizes like 16x16 and 32x32
pixels? (In Windows, this is useful, as the icon in the window of the
frame has usually size 16x16 while the icon as shown when you press Alt
+Tab to switch between several application has 32x32 pixels.)

Thank you, Dan

 
Reply With Quote
 
 
 
 
Larry Barowski
Guest
Posts: n/a
 
      02-11-2007

"Dan Polansky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hello, in Swing, how can I achieve that a frame icon has several
> images associated with it, in different sizes like 16x16 and 32x32
> pixels? (In Windows, this is useful, as the icon in the window of the
> frame has usually size 16x16 while the icon as shown when you press Alt
> +Tab to switch between several application has 32x32 pixels.)


In Java 1.6 you can use Window.setIconImages(). For older
versions of Java you'd have to do it using JNI for each
platform.


 
Reply With Quote
 
 
 
 
Dan Polansky
Guest
Posts: n/a
 
      02-11-2007
On Feb 11, 2:54 pm, "Larry Barowski" <MElarrybar-AT-
eng_DOT_auburnANOTHERDOTeduEND> wrote:
> "Dan Polansky" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) oups.com...
>
> > Hello, in Swing, how can I achieve that a frame icon has several
> > images associated with it, in different sizes like 16x16 and 32x32
> > pixels? (In Windows, this is useful, as the icon in the window of the
> > frame has usually size 16x16 while the icon as shown when you press Alt
> > +Tab to switch between several application has 32x32 pixels.)

>
> In Java 1.6 you can use Window.setIconImages(). For older
> versions of Java you'd have to do it using JNI for each
> platform.


Larry, that is a good news. Do you know or have a link on how to do it
using JNI, at least for Windows? Dan

 
Reply With Quote
 
Larry Barowski
Guest
Posts: n/a
 
      02-12-2007

"Dan Polansky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Larry, that is a good news. Do you know or have a link on how to do it
> using JNI, at least for Windows? Dan


Following is what I use to load small and large icons from a
..ico file. I stripped out a caching mechanism, so it may not
compile as-is. Of course, if you've never used jni you'll have
to figure that out as well.

JNIEXPORT void JNICALL Java_nativ_W32Native_setIconX(JNIEnv *env,
jclass obj, jobject wnd, jstring icon_path) {
JAWT awt;
awt.version = JAWT_VERSION_1_3;
if(JAWT_GetAWT(env, &awt) == JNI_FALSE)
return;

JAWT_DrawingSurface *ds = awt.GetDrawingSurface(env, wnd);
if(ds == NULL)
return;

jint lock = ds->Lock(ds);
if((lock & JAWT_LOCK_ERROR) != 0) {
awt.FreeDrawingSurface(ds);
return; }

JAWT_DrawingSurfaceInfo *dsi = ds->GetDrawingSurfaceInfo(ds);
if(dsi != NULL) {
JAWT_Win32DrawingSurfaceInfo *dsi_win =
(JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
HWND win_handle = dsi_win->hwnd;
if(win_handle != NULL) {
LPTSTR icon_path_str = (LPTSTR)GetString(env, icon_path);
HICON icon, icon_sm;
bool found = false;
icon = (HICON)LoadImage(NULL, icon_path_str, IMAGE_ICON,
GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
LR_LOADFROMFILE);
icon_sm = (HICON)LoadImage(NULL, icon_path_str, IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
LR_LOADFROMFILE);
if(icon != NULL)
SendMessage(win_handle, WM_SETICON, ICON_BIG, (long)icon);
if(icon_sm != NULL)
SendMessage(win_handle, WM_SETICON, ICON_SMALL, (long)icon_sm);

ReleaseString(env, icon_path, icon_path_str);
}
ds->FreeDrawingSurfaceInfo(dsi);
}

ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Win 7 changing font sizes without icon sizes? why? Computer Support 0 03-21-2010 11:32 AM
Re: Win 7 changing font sizes without icon sizes? why? Computer Support 0 03-21-2010 11:31 AM
Relationship between image, paper, and frame sizes Don Tuttle Digital Photography 5 10-28-2009 07:58 PM
The File Sizes of Pictures on my CDs Increased to Unreadable Sizes Marful Computer Support 11 03-08-2006 07:13 PM
digital photography and frame sizes larrylook Digital Photography 21 01-02-2005 09:50 PM



Advertisments