样式的JavaFX图像路径



我目前正在尝试使用JavaFX制作一个自定义按钮。我定义了两种样式,其中包含两种不同的图像,用于两种按钮状态(按下和释放(。我使用Intellij Idea,当定义路径时,它没有显示错误,但按钮没有显示。它只是透明的,但我可以点击它。我尝试过指定的不同路径,但没有得到任何结果。这是我定义样式和文件树的代码。谢谢

public class CustomButton extends Button {
private final String FONT_PATH = "src/Resources/GUI/pixelFont.ttf";
private final String BUTTON_PRESSED_STYLE = "-fx-background-color: transparent;" +
" -fx-background-image: url('../../Resources/GUI/Buttondown.png');";
private final String BUTTON_FREE_STYLE = "-fx-background-color: transparent;" +
" -fx-background-image: url('../../Resources/GUI/Buttonup.png');";
public CustomButton(String text) {
setFont();
setPrefWidth(180);
setPrefHeight(53);
setText(text);
setStyle(BUTTON_PRESSED_STYLE);
initButtonListeners();
}
}

文件树

将所有文件移动到Intellij Idea预先生成的资源文件夹中,然后使用该文件夹解决了问题。

最新更新