【发布时间】:2018-03-03 12:29:36
【问题描述】:
我正在尝试制作一个简单的程序,在网格窗格中显示 4 张图像。我在那里没有问题,但是一旦我尝试添加第二个,我就会遇到一些问题。这是我的代码:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
GridPane gridPane = new GridPane();
gridPane.add(new ImageView(new Image ("http://gifimage.net/wp-content/uploads/2017/06/american-flag-gif-13.gif")), 1,1);
gridPane.add(new ImageView(new Image ("http://bestanimations.com/Flags/Asia/china/chinese-flag-waving-gif-animation-10.gif")), 2,2);
Scene scene = new Scene(gridPane, 1000, 500);
primaryStage.setTitle("Flags");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
我认为图像后面的行和列可能有问题,但我尝试了一些方法并没有成功。任何帮助是极大的赞赏。谢谢
【问题讨论】:
-
抱歉,遇到问题我的意思是根本不会显示第二张图片。我添加了一个屏幕截图。
-
hmmm 我认为这可能是标志本身的图像。我注意到中国国旗是透明的;可能与此有关。
-
使用两个美国国旗,你的代码就可以工作了。
标签: java image javafx gridpane