Scala-swing ... adding Panel

Hi Everyone,
Here is an extract of code from the (36 line) snippet accompanying this question.

val drawPanel = new Panel {
preferredSize = new Dimension(500, 500)
background = new Color(255, 0, 0) // RED

val frame = NewMainFrame {
contents = new BorderPanel {
layout += (drawPanel) // how to fix error ? (this is line 24 in snippet)

Line 24 has an error as follows …
Found: drawPanel scala.swing.Panel
Required: scala.swing.Component, Constraints

Researching further it seems that BorderPanel.layout is declared as Map[Component, Constraints]

Also docs say object BorderPanel has “Classlikes” for another object, namely Position.

I assume I need a “Constraints” or a “Position”, but how do I create it to eliminate error.

Thanks ~ JohnP

I am progressing further :slight_smile: I am now able to answer my own question above …
What I needed to change is …
layout += (button → BorderPanel.Position.South)
layout += (drawPanel → BorderPanel.Position.North)
… however, this has now uncovered another problem.
Scatsie now gives an error on the line declaring val frame = New MainFrame
No X11 DISPLAY variable was set

Extra Info:
This code snippet does run in Visual Studio Code OK
echo $DISPLAY on my Linux machine gives “:1”
The program xeyes works and follows my mouse (X11 test)
Both Chrome and Firefox Browsers behave the same behaviour

Can anyone help with “No X11 DISPLAY variable set” error ?

1 Like

That is most likely a limitation of Scastie. I don’t think it would have Linux environment variables.

You can’t expect Scastie to be able to run a Swing app; a website doesn’t have access to your local windowing environment.

SUCCESS :slight_smile:
Thank you SpamEgg1 and SethTisue for your insight.
scala-cli HelloWorld.scala at the local command prompt does give the expected result.

In case anyone else would like this scala 3.0.0 HelloWorld.scala code I include the code snippet below …