尝试使用Scala.Swing并排显示两个图像的新手
我正在尝试制作一个可以翻页的应用程序 我希望这段代码能够并排显示两个图像(001.jpg,002.jpg),但是我没有得到任何结果尝试使用Scala.Swing并排显示两个图像的新手,swing,scala,Swing,Scala,我正在尝试制作一个可以翻页的应用程序 我希望这段代码能够并排显示两个图像(001.jpg,002.jpg),但是我没有得到任何结果 import java.awt.Dimension import javax.swing.ImageIcon import scala.swing.event.UIElementResized import scala.swing.{BorderPanel, BoxPanel, Label, MainFrame, Orientation, SimpleSwingA
import java.awt.Dimension
import javax.swing.ImageIcon
import scala.swing.event.UIElementResized
import scala.swing.{BorderPanel, BoxPanel, Label, MainFrame, Orientation, SimpleSwingApplication}
object CViewerMainWindow extends SimpleSwingApplication {
var i = 0
def drawPages(left: Label, right: Label, size: Dimension): Unit = {
//resize to match window
}
def top = new MainFrame {
title = "Work in Progress"
preferredSize = new Dimension(320, 240)
var leftPage = new Label {new ImageIcon("/Users/Matt/learning-scala/learning-GUI/001.jpg")}
var rightPage = new Label {new ImageIcon("/Users/Matt/learning-scala/learning-GUI/002.jpg")}
// maximize
visible = true
// contents = new BorderPanel {
// layout(leftPage) = BorderPanel.Position.West
// layout(rightPage) = BorderPanel.Position.East
// }
contents = new BorderPanel {
layout(new BoxPanel(Orientation.Vertical) {
contents += leftPage
}) = BorderPanel.Position.West
layout(new BoxPanel(Orientation.Vertical) {
contents += rightPage
}) = BorderPanel.Position.East
}
// contents = new Label("Here is the contents!")
listenTo(this)
reactions += {
case UIElementResized(source) =>
println(source.size)
drawPages(leftPage, rightPage, size)
}
}
}
我用替换的方法解决了这个问题
var leftPage = new Label {
new ImageIcon("/Users/Matt/learning-scala/learning-GUI/001.jpg")
}
var rightPage = new Label {
new ImageIcon("/Users/Matt/learning-scala/learning-GUI/002.jpg")
}
使用此代码
var leftPage = new Label {
icon = new ImageIcon("/Users/Matt/learning-scala/learning-GUI/001.jpg")
}
var rightPage = new Label {
icon = new ImageIcon("/Users/Matt/learning-scala/learning-GUI/002.jpg")
}
显然,您必须将其图标设置为所需的ImageIcon,而不是仅为标签指定ImageIcon