英文:
Why am i getting a missing method error for javafx.scene.layout.Background.fill in javafx for certain JDK 17/JavaFX 17 distributions?
问题
我有一些代码,使用 Azul Zulu SDK (17.0.8+7) 并带有 FX 捆绑包可以正常工作。
但是,如果我使用未捆绑的 Azul Zulu SDK (17.0.8+7) 并引用 Gluon JavaFX SDK,我会得到以下错误。
在线程 "JavaFX Application Thread" 中发生异常 java.lang.NoSuchMethodError: 'javafx.scene.layout.Background javafx.scene.layout.Background.fill(javafx.scene.paint.Paint)';
这个问题在 Liberica JDK 17.0.8+7 FX 捆绑版本中也存在。
似乎 fill
方法在 Zulu JDK 中带有 FX 捆绑,但在单独的 Gluon Library 或 Liberica FX 捆绑 JDK 中不可用。
请问有人能解释一下为什么会这样吗?是否有可能在没有访问 fill
方法的情况下实现相同的效果?
void setgradient(Pane bpane, boolean b, String color)
{
if (b)
{
bpane.setBackground(Background.fill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#5e89b1")), //colors
new Stop(1, Color.web("#68a5de")))));
}
else
{
bpane.setBackground(Background.fill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#7d7b75")), //colors
new Stop(1, Color.web("#dedbd3")))));
}
}
英文:
I have some code which works fine using the Azul Zulu SDK (17.0.8+7) with FX bundled.
However if i take the unbundled Azul Zulu SDK (17.0.8+7) and reference the Gluon JavaFX SDK. I get the following error.
> Exception in thread "JavaFX Application Thread" java.lang.NoSuchMethodError: 'javafx.scene.layout.Background javafx.scene.layout.Background.fill(javafx.scene.paint.Paint)'
This problem persists in the Liberica JDK 17.0.8+7 FX bundled version as well.
It appears that the fill method is available in the Zulu JDK with FX bundled but not in the serparate Gluon Library or the Liberica FX bundled JDK.
Plese can someone explain please why this is and is it possible to achieve the same without access to the fill method.
void setgradient(Pane bpane, boolean b, String color)
{
if (b)
{
bpane.setBackground(Background.fill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#5e89b1")), //colors
new Stop(1, Color.web("#68a5de")))));
}
else
{
bpane.setBackground(Background.fill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#7d7b75")), //colors
new Stop(1, Color.web("#dedbd3")))));
}
}
答案1
得分: 2
我已找到问题,
public static Background fill(Paint fill) {
return new Background(new BackgroundFill(fill, null, null));
}
是在JavaFX 18中引入的一个便利方法。不确定为什么Azul Java 17.0.8捆绑了FX的18版本?
这段代码解决了这个问题。
void setgradient(Pane bpane, boolean b, String color)
{
if (b)
{
Background bg = new Background(new BackgroundFill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#5e89b1")), //colors
new Stop(1, Color.web("#68a5de"))), null, null));
bpane.setBackground(bg);
}
else
{
Background bg = new Background(new BackgroundFill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#7d7b75")), //colors
new Stop(1, Color.web("#dedbd3"))), null, null));
bpane.setBackground(bg);
}
}
英文:
I've found the problem,
public static Background fill(Paint fill) {
return new Background(new BackgroundFill(fill, null, null));
}
is a convenience method introduced in JavaFX 18. Not sure why version 18 of the FX is bundled in with Azul Java 17.0.8 ?
This code gets around the problem.
void setgradient(Pane bpane, boolean b, String color)
{
if (b)
{
Background bg = new Background(new BackgroundFill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#5e89b1")), //colors
new Stop(1, Color.web("#68a5de"))), null, null));
bpane.setBackground(bg);
}
else
{
Background bg = new Background(new BackgroundFill(new LinearGradient(
0, 0, 1, 1, true, //sizing
CycleMethod.NO_CYCLE, //cycling
new Stop(0, Color.web("#7d7b75")), //colors
new Stop(1, Color.web("#dedbd3"))), null, null));
bpane.setBackground(bg);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论