小编Dav*_*šta的帖子

JavaFX按钮背景图像

我在JavaFX中的按钮上设置backgroundImage时遇到问题.

Image newGame = new Image("File:/CSS/nova_hra.png");
BackgroundImage newGameBgr = new BackgroundImage(newGame, null, null, null, null);

Button buttonNewGame = new Button("Nová Hra");
Button buttonLoadGame = new Button("Na?íst Hru");
Button buttonStatistics = new Button("Statistiky");
Button buttonExit = new Button("Konec");

buttonNewGame.setGraphic(new ImageView(newGame));
//buttonNewGame.setBackground(new Background(newGameBgr));

buttonExit.setMinHeight(40);
buttonLoadGame.setMinHeight(40);
buttonNewGame.setMinHeight(40);
buttonStatistics.setMinHeight(40);

buttonExit.setMinWidth(120);
buttonLoadGame.setMinWidth(120);
buttonNewGame.setMinWidth(120);
buttonStatistics.setMinWidth(120);
Run Code Online (Sandbox Code Playgroud)

这对buttonNewGame没有任何作用.每次我尝试用这个加载图像

Image image = new Image(getClass().getResourceAsStream("a.png"));
Run Code Online (Sandbox Code Playgroud)

我得到了runTime异常.我用的时候

Image image = new Image(getClass().getResourceAsStream("a.png"));
Run Code Online (Sandbox Code Playgroud)

整个形象不顾一切.

background javafx image button

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

background ×1

button ×1

image ×1

javafx ×1