Search code examples
swingscalascala-swing

swing issues in scala


i'm looking at some example code that is erroring out in scala 2.9.1:

import javax.swing.JFrame
import javax.swing.JMenuBar
import javax.swing.JButton
import javax.swing._

import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
import javax.swing.{UIManager}
object UI extends SimpleSwingApplication {   
    UIManager.setLookAndFeel(new NimbusLookAndFeel)  
}

error: /some/path/Cls.scala:25: error: not found: type SimpleSwingApplication


Solution

  • turns out i had to run my code like so:

    scala -classpath /usr/share/java/scala-swing.jar Cls.scala

    the code base that was successful is:

    import javax.swing.JFrame
    import javax.swing.JMenuBar
    import javax.swing.JButton
    import javax.swing._
    import scala.swing.SimpleSwingApplication
    import scala.swing._
    
    
    object UI extends SimpleSwingApplication {   
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())  
        def top = new MainFrame {
          title = "First Swing App"
          contents = new Button {
            text = "Click me"
          }
        }
    
        def main() {
            println("hi")
        }
    }