0

How can you set a new frame icon on Scala’s scala.swing.Frame class? What are the intentions behind Frame.iconImage: Image and Frame.iconify()? I can’t figure out, what they’re doing.

Here’s my last attempt

import scala.swing.Frame

class MyFrame extends Frame {
  iconImage = toolkit.getImage("src/main/resources/icon.png")
  visible = true
}

I also tried several other methods, but nothing worked.

pvorb
  • 7,157
  • 7
  • 47
  • 74

2 Answers2

1

What you have there should work, but if the getImage can't find the file, it fails silently. Since you have a relative path, it's probably because you code isn't executing in the directory you intended.

On Ubuntu this should highlight the difference. I get one window with a smiley icon and one with the standard java icon.

new Frame() {
  iconImage = toolkit.getImage("/usr/share/icons/gnome/16x16/emotes/stock_smiley-10.png")
  size = new Dimension(200, 200)
  visible = true
}
new Frame() {
  iconImage = toolkit.getImage("xxx")
  size = new Dimension(200, 200)
  visible = true
}
Sue C
  • 326
  • 1
  • 3
0

I'm guessing you are on OS X. Sadly, the icon decoration does not work for the OS X look and feel, neither does it work for Nimbus look and feel which seems to not come with a specific window decoration (uses title bar from OS X).

So you will need a look and feel that does paint its own window title bar:

import scala.swing._
import javax.swing._
UIManager.setLookAndFeel(new plaf.metal.MetalLookAndFeel)
JFrame.setDefaultLookAndFeelDecorated(true)

val f = new Frame {
   iconImage = toolkit.getImage(new java.net.URL(
      "http://www.scala-lang.org/sites/default/files/favicon.gif"))
   size = new Dimension(200, 200)
   visible = true
}

The only chance with OS X window title bars is if you want to decorate with the default icon used for a particular file.

Look for Window.documentFile here: http://developer.apple.com/library/mac/#technotes/tn2007/tn2196.html#//apple_ref/doc/uid/DTS10004439

0__
  • 66,707
  • 21
  • 171
  • 266
  • “[…] neither does it work for Nimbus look and feel […]”. That’s it. I am using Nimbus, but didn’t mention that here. – pvorb Jul 03 '12 at 14:13
  • cf. http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=a655306f41e2c17d50e0bf54ea6?bug_id=6675399 -- don't know if they did anything about it in Java 7 (I'm stuck to Java 6 Apple) – 0__ Jul 03 '12 at 14:20
  • No they didn’t. I’m using Java 7. – pvorb Jul 03 '12 at 14:28