I have to add HBox to GridPane. If I add HBox to GridPane in same class then the system display correctly. But when I try with two classes, only empty window display.I'm new to javafx..How can I do that please help me thanks.
public class IpCamMainWindow extends Application{
private static ArrayList<IpCamViewer> ipCameraList = new ArrayList<IpCamViewer>();
private static ArrayList<String> urls= new ArrayList<String>();
GridPane grid =null;
private ImageView imgWebCamCapturedImage;
private BufferedImage grabbedImage;
private ObjectProperty<Image> imageProperty = new SimpleObjectProperty<Image>();
private Webcam webCam = null;
private boolean stopCamera = false;
IPview ipCamViewer=null;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(0, 10, 0, 10));
for(int i=0;i<4;i++){
ipCamViewer = new IPview();
grid.add(ipCamViewer, i%2, i/2);
System.out.println("column: " + i%2 + ", row: " + i/2);
}
Scene scene = new Scene(grid);
stage.setScene(scene);
stage.setTitle("IP Camera Solution");
stage.show();
}
}
-
public class IPview extends HBox {
private ImageView imgWebCamCapturedImage;
private BufferedImage grabbedImage;
private ObjectProperty<Image> imageProperty = new SimpleObjectProperty<Image>();
HBox hbox;
public IPview(){
HBox hbox=addHBox();
}
public HBox addHBox() {
hbox = new HBox();
hbox.setPadding(new Insets(15, 12, 15, 12));
hbox.setSpacing(10);
hbox.setStyle("-fx-background-color: #336699;");
Button buttonCurrent = new Button("Current");
buttonCurrent.setPrefSize(100, 20);
Button buttonProjected = new Button("Projected");
buttonProjected.setPrefSize(100, 20);
hbox.getChildren().addAll(buttonCurrent, buttonProjected);
return hbox;
}
}
IPViewis aHBox(inheritance:public class IPView extends HBox) or ifIPViewhas aHBox(aggregation:HBox hbox). Right now you have both, and you add the buttons to the aggregatedHBox, but you add theIPViewitself (which contains no buttons) to theGridPane. - James_DHBoxas a field inIPView- James_D