2016-06-25 2 views
0

Я пытаюсь создать приложение, в котором вы можете пролистывать страницы.Новичок пытается отобразить два изображения рядом с помощью Scala.Swing

Я надеялся, что этот код будет отображать два изображения (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, 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) 
     } 
    } 
} 

ответ

1

Я исправили проблему, заменив

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 вас хотеть.

Смежные вопросы