带有scala.swing的JInternalFrame

Arn*_*rne 0 swing scala wrapper jinternalframe scala-swing

scala swing看起来很有趣,但不知何故它是不完整的,有时我仍然需要使用旧的java类,但我不知道如何正确地包装它们.

那么如何正确包装javax.swing.JInternalFrame以便我可以在MainFrame中将它用作Component?

我试着让这个例子与scala和scala swing库一起工作,我终于设法获得了一个内部框架,但我的MainFrame扭曲了所有内部框架并将它们拉伸直到它们具有与内部空间完全相同的宽度和高度.主机上.

这是我目前的实施:

import swing._
import event._

object InternalFrameDemo extends SimpleSwingApplication{

    val top = new MainFrame{
        title = "InternalFrameDemo"
        preferredSize = new Dimension(640,480)

        val menuNew = new MenuItem("New"){
            mnemonic = Key.N
            action = new Action("new"){
                def apply(){
                    createFrame
                }
            }
        }

        val menuQuit = new MenuItem("Quit"){
            mnemonic = Key.Q
            action = new Action("quit"){
                def apply(){
                    quit()
                }
            }
        }

        menuBar = new MenuBar{
            contents += new Menu("Document"){
                mnemonic = Key.D
                contents ++= Seq(menuNew,menuQuit)
            }
        }

        def createFrame{
            val newFrame = MyInternalFrame()
            newFrame.visible = true
            contents = newFrame
        }
    }
}

object MyInternalFrame{
    var openFrameCount = 0;
    val xOffset, yOffset = 30;

    def apply() = {
        openFrameCount += 1
        val jframe = new javax.swing.JInternalFrame("Document #" + openFrameCount,true,true,true,true)

        jframe.setSize(300,300)
        jframe.setLocation(xOffset*openFrameCount,yOffset*openFrameCount)

        Component.wrap(jframe)
    }
}
Run Code Online (Sandbox Code Playgroud)

zig*_*tar 6

以下内容定义于Component:

def wrap (c: JComponent): Component 
Run Code Online (Sandbox Code Playgroud)

所以你写Component.wrap(new JInternalFrame).