问题标签 [scala-swing]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
165 浏览

scala-swing - 使用 setAlignmentX 对齐 Scala MainFrame 中的按钮

我无法让简单的 Scala MainFrame GUI 上的按钮在中心对齐。尝试了许多 buttonname.peer.setAlignmentX 和 Y 的组合,但没有任何效果。

代码如下:

谁能指出我对 setAlignmentX,Y 用法的任何描述。ScalaDoc 会有使用示例吗?

0 投票
1 回答
227 浏览

scala - 更改时自动更新按钮文本

我目前正在学习 scala,并使用基本的 scala swing UI 制作加密程序。我添加了 2 个摆动按钮,其文本由 2 个 var 保存。

代码如下所示:

这些“文本”变量会在加密/解密过程中通过各种方法经常更改,但是当它们发生更改时,按钮上显示的文本不会。

我想知道一种方法,使按钮的显示文本在包含该文本的 var 发生更改时自动更改。

非常感谢您的洞察力:)

0 投票
1 回答
410 浏览

swing - Scala SimpleSwingApplication not repainting

I have a simple swing application in Scala. Work is done by a separate object but progress must be periodically reported to the GUI which launched it. The problem is that the updates are only visible once the Thread has completed its task. I've tried adding various calls to repaint() top.peer.repaint() and Thread.sleep(0) all to no avail and all the while feeling that the fact that I'm resorting to adding these is a sign I'm doing something wrong.

I remember struggling and overcoming this issue with this back when I used to develop in Java and have tried to structure my solution based on what I recall being the right approach but I must be missing something.

Here is a simple example which reproduces the problem:

Update I've accepted the answer which drew attention to the cause of the problem. I stupidly thought that since the worker was a Runnable that EventQueue.invokeLater would spawn a separate thread for it. I have been pointed in the direction of Swing Worker which is probably the right way to go.

0 投票
2 回答
730 浏览

scala - 如何在 Scala 中创建选项对话框

我一直在尝试创建一个不限于两个或三个选项(Option.YesNo 或 Option.YesNoCancel)的选项对话框,但是除了这些内置选项之外,我找不到使用任何东西的方法。具体来说,以下内容拒绝接受我可以为 optionType 输入的任何内容:

0 投票
1 回答
900 浏览

java - Scala摇摆重绘

所以我对scala非常非常陌生。我正在使用 GUI 实现 Conways 的生命游戏。我不知道如何让我的面板在 2D 数组更改时更新。有人可以指出我正确的方向吗?我的整个代码如下:

0 投票
1 回答
663 浏览

swing - 在 Scala 中,Swing 组件随着 TextArea 的填充而移动

我在 BoxPanel 中遇到了对齐的基本问题。当任一 TextAreas 接受输入时,面板中的其他组件(不是面板的宽度)会随着字符移动。

我的错误是什么?谢谢!

空白文本区域

填充文本区域

0 投票
1 回答
263 浏览

scala - scala,swing:事件调度线程(actors)的线程问题

我有一个继承自 SimpleSwingApplication 的 scala 类。这个类定义了一个窗口(带有def top = new MainFrame)并实例化了一个演员。演员的代码很简单:

并且主类也使用“substance”,一个允许 gui 自定义的 API(没有更多丑陋的摇摆控件!)。

当我用鼠标离开给定的秋千桌时,演员被调用;然后调用actor并取消选择表的所有行。演员表现得很好,但是当我启动我的程序时,每次调用演员时,我都会收到以下错误消息:

org.pushingpixels.substance.api.UiThreadingViolationException:必须在事件调度线程上进行状态跟踪

你知道我怎样才能删除这个错误信息吗?

0 投票
2 回答
1825 浏览

scala - Scala:if语句在闭包中返回Any而不是Unit

我在方法中有以下代码:

paintSeq 在方法外声明

这将按预期编译和运行。但是,如果我在第一种情况下添加 if 语句:

我收到一个错误:

类型不匹配; 找到:Seq[swing.Graphics2D => Any] 需要:Seq[swing.Graphics2D => Unit] AreaESw.scala /prStratSw/src/pGrid/pUISw 第 49 行 Scala 问题

该错误与paintSeq :+= 方法有关。为什么 if 语句返回 Any 而不是 Unit?我可以通过在 if 语句后添加一行来消除错误:

但是,如果我在最后添加返回单元:

它编译时出现以下警告:

封闭方法 setVisObjs 具有结果类型 Unit:返回值被丢弃

但是当它运行时出现以下错误

线程“AWT-EventQueue-0”中的异常 scala.runtime.NonLocalReturnControl$mcV$sp

使用“return()”仍然会产生运行时异常。

这是 Scala Swing 代码,但我在 JavaFx Eclipse 下载中使用 Scala 2.10.3:Linux 上的 4.2.2。

0 投票
1 回答
278 浏览

scala - 如何在 Scala 中检测 CTRL+S 等键盘快捷键

我想在 Scala 中检测像 CTRL+S 这样的键盘快捷键。如果只按下一个键很容易,但如果按下两个或多个键似乎很难。有没有比以下更好的解决方案?

KeyPressed感觉在语义上有点不正确,因为它检查是否在释放 S 按钮后按下了 CTRL 按钮(我认为使用or并没有更好KeyTyped)。

这是一个SSCE

0 投票
0 回答
76 浏览

swing - Scala ListViewSelectionChange event outputs unexpected range

I'm currently trying to use a scala.swing.ListView in a Scala application.

I basically want to get the selected item of a ListView, as soon as the selection changes.

Here a sample which can be pasted into the Scala prompt.

If I would now select the first element in the list, I would expect Range to contain only 0, if I then select the second element, I would expect only 1 and so on.

However, if I select the first and then the second element, Range contains (0, 1). If I select the fifth and then the third element, range contains (2, 3, 4).

So, range contains always the range between the last and the current selected item, in ascending order.

Sadly, the Scala documentation does not state how this API works.

Does anyone know what I'm doing wrong here? Might this be the wrong event for reacting on ListView selection changes?