2011-05-12 73 views

回答

2

如果您想知道如何將一個JSpinner添加到Scala swing應用程序中,您需要使用Component.wrap(JComponent)來獲得一個Scala組件。這應該給你的東西模型:

import swing._ 

import javax.swing.SpinnerListModel 
import javax.swing.JSpinner 

object SpinnerDemo extends SimpleSwingApplication { 
    val monthStrings: Array[Object] = Array("January", "February", "March", 
    "April", "May", "June", "July", 
    "August", "September", "October", 
    "November", "December") 

    def top = new MainFrame { 
    title = "Spinner Demo" 

    val monthModel = new SpinnerListModel(monthStrings) 
    val spinner = new JSpinner(monthModel) 
    contents = new FlowPanel { 
     contents += new Label("Month") 
     contents += Component.wrap(spinner) 
    } 
    } 
} 
0

這並不容易。

[error] /home/ciembor/projekty/VirtualCut/src/main/scala/View/View.scala:22: reference to Action is ambiguous; 
[error] it is imported twice in the same scope by 
[error] import javax.swing._ 
[error] and import swing._ 

swingjavax.swing是相互矛盾的。我想我應該只輸入JSpinner班。

+0

有趣。我的答案中的代碼編譯並使用scala 2.9.0正確運行。我會編輯我的答案,並使進口更緊一點。 – 2011-05-17 18:16:33