1
我有一個顯示窗口的應用程序。當用戶按下「關閉」按鈕而不是關閉窗口時,我只想隱藏這個窗口,我該怎麼做?當用戶點擊窗口的關閉按鈕時隱藏框架而不是關閉
這裏是我的代碼(這是行不通的,在應用上點擊關閉):
object UxMonitor {
def main(args: Array[String]) {
val frame = new MainScreen()
frame.peer.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE)
initTrayIcon(frame.peer)
}
....
class MainScreen extends MainFrame {
private val HEADERS = Array[Object]("Security", "Last Price", "Amount", "Cost")
private val quotes = new Quotes()
private val tableModel = new DefaultTableModel()
title = "UX Monitor"
tableModel.setColumnIdentifiers(HEADERS)
private val table = new Table {
model = tableModel
}
contents = new ScrollPane {
contents = table
}
quotes.setListener(onQuotesUpdated)
quotes.startUpdating
peer.addWindowListener(new WindowAdapter{
def windowClosing(e : WindowEvent){
self.setVisible(false)
}
})
pack
嘗試設置默認的關閉操作DO_NOTHING_ON_CLOSE但設置在MainScreen類,並留下你的窗口監聽器是。 – eSuarez
這個框架應該可能是一個對話框。請參閱[使用多個JFrames,好/壞實踐?](http://stackoverflow.com/a/9554657/418556) –