8

I want to play around with some image manipulation code I'm writing, so I'd like to use the Scala console or something like BlueJ's Java CodePad to create a java.awt.Image and then just pop it up to look at.

Ideally, it'd just be a panel or something without a Frame that would appear and I could just click it to make it disappear. Is there a way to make something that lightweight, or do I really need some kind of frame and more scaffolding?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Todd O'Bryan
  • 2,234
  • 17
  • 30

2 Answers2

9
JOptionPane.showMessageDialog(parent, new JLabel(new ImageIcon(theImage)));

Of course, if you have an URL for the image (or can form one from a File path), it can also be displayed as a tool-tip using HTML.

See Show full Image when hover over thumbnail for source.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
6

In Scala, use the Java Swing ImageIcon

val img = new ImageIcon("path/to/file.jpg")

with Scala Swing Dialog

Dialog.showMessage(message = img)

Or better, display the image instead of the alert icon:

Dialog.showMessage(message = null, icon = img)
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180