0

I am trying to set the application icon for a simple scala swing application. I set the MainFrame.iconImage but that seems to have no effect. The application's icon in the windows taskbar and the window frame is still the java logo.

Here is the test code I am using.

package uiTest

import swing._
import swing.event._
import Swing._
import javax.swing._

object HelloWorld extends SimpleSwingApplication {

  def top = new MainFrame {

    title = "Hello World"
    preferredSize = new Dimension(200, 200)

    iconImage = toolkit.getImage("/Logo.png") // does nothing.
    println(iconImage.getWidth(peer)) // -1

    contents = new BoxPanel(Orientation.Vertical) {
      contents += new Label {
        // successfully displays my logo so no resource issues.
        icon = new ImageIcon(getClass.getResource("/Logo.png"))
      }
    }
  }
}

My only idea left is that Frame.iconImage has nothing to do with the application icon. In that case, where do I set the application icon? An then what does Frame.iconImage do then?

This question indicated that it was not possbile on OSX. Is that the same on Windows?

cheezsteak
  • 2,731
  • 4
  • 26
  • 41

1 Answers1

1

In the code that works you're using getResource, indicating that the file is located in your resource directory, but when you try to set the icon, you're using the path "/Logo.png" directly, indicating that it's located in the root directory.

sepp2k
  • 363,768
  • 54
  • 674
  • 675