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

Discussion in 'Java' started by Dan Polansky, Feb 11, 2007.

  1. Dan Polansky

    Dan Polansky Guest

    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
    Dan Polansky, Feb 11, 2007
    #1
    1. Advertising

  2. "Dan Polansky" <> wrote in message
    news:...
    > 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 Barowski, Feb 11, 2007
    #2
    1. Advertising

  3. Dan Polansky

    Dan Polansky Guest

    On Feb 11, 2:54 pm, "Larry Barowski" <MElarrybar-AT-
    eng_DOT_auburnANOTHERDOTeduEND> wrote:
    > "Dan Polansky" <> wrote in message
    >
    > news:...
    >
    > > 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
    Dan Polansky, Feb 11, 2007
    #3
  4. "Dan Polansky" <> wrote in message
    news:...
    > 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);
    }
    Larry Barowski, Feb 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miro Durcik

    app.rc resource's icon to .net Icon

    Miro Durcik, Oct 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,377
    Miro Durcik
    Oct 9, 2004
  2. coleenholley
    Replies:
    5
    Views:
    1,125
    coleenholley
    Jan 21, 2004
  3. Sonnich Jensen

    inline frame and sizes

    Sonnich Jensen, Jun 12, 2007, in forum: HTML
    Replies:
    2
    Views:
    351
    jodleren
    Jun 21, 2007
  4. Jochen Califice

    Window sizes NN6.x or higher

    Jochen Califice, Jun 29, 2003, in forum: Javascript
    Replies:
    2
    Views:
    107
    Martin Honnen
    Jun 29, 2003
  5. Bodi
    Replies:
    1
    Views:
    268
    Lasse Reichstein Nielsen
    Nov 18, 2003
Loading...

Share This Page