reset password
Author Message
AB4586170
Posts: 19
Posted 22:28 Oct 05, 2018 |

I input the hBox button features on my code for the TicTacToePane file and it still won't show the buttons. Is there anything missing from the hBox code?

Attachments:
jroble52
Posts: 15
Posted 22:31 Oct 05, 2018 |

I think your Button should be imported from javafx instead of swing

AB4586170
Posts: 19
Posted 22:34 Oct 05, 2018 |

I tried, but it would still not show and would give me syntax errors. I don't know if I need to make a separate file for this. What's the correct syntax for setting button sizes.

Last edited by AB4586170 at 22:37 Oct 05, 2018.
jlopez172
Posts: 6
Posted 22:39 Oct 05, 2018 |

You need to rearrange the GUI

First you have to extend BorderPane from TicTacToePane instead of GridPane, then you create a GridPane object and add it to the center of the BorderPane and the Hbox to the top. Remember to change the "add()" to "[gridPaneVar].add()" since it is not extending GridPane anymore. Hope it works!

jroble52
Posts: 15
Posted 22:44 Oct 05, 2018 |

Then I think it might be because you're not actually using the addHBox method anywhere. Going off of what jlopez said, you'd want to set that returned HBox somewhere on the BorderPane using one of the setTop, setBottom, setLeft, setRight, or setCenter methods that come with BorderPane.

AB4586170
Posts: 19
Posted 22:47 Oct 05, 2018 |

That means I have to create a separate method for the top part with the buttons?

jlopez172
Posts: 6
Posted 22:55 Oct 05, 2018 |

No, once your Class extends BorderPane, those methods are ready for you to use so you can add anything to Center, Top, etc. Then you can do "setTop(Hbox)" and "setCenter(grid)" for example

AB4586170
Posts: 19
Posted 22:55 Oct 05, 2018 |

In what part is BorderPane?

Last edited by AB4586170 at 22:56 Oct 05, 2018.
jlopez172
Posts: 6
Posted 23:02 Oct 05, 2018 |

import javafx.scene.layout.BorderPane;

AB4586170
Posts: 19
Posted 23:04 Oct 05, 2018 |

So basically I have to change from … extends GridPane to … extends BorderPane?

Last edited by AB4586170 at 23:07 Oct 05, 2018.
jlopez172
Posts: 6
Posted 23:11 Oct 05, 2018 |

Yes, and after making the change fix all those "add()" errors you'll see. You have to create a new GridPane object inside the class and then add it to the add() like grid.add() for all of them

AB4586170
Posts: 19
Posted 23:17 Oct 05, 2018 |

It gave a logic error. The entire pane opened blank. In what method does the GridPane object go? Here is the updated java file for TicTacToePane.java

Attachments:
Last edited by AB4586170 at 23:18 Oct 05, 2018.
jlopez172
Posts: 6
Posted 23:29 Oct 05, 2018 |

Everything looks fine but I recommend putting the new GridPane object outside the method. Put it right below Game g; and then you just need to add the grid to the border pane with “setCenter(grid)” after the for loop in SetUpLabels

AB4586170
Posts: 19
Posted 23:54 Oct 05, 2018 |

Still giving me a logic error. Grid only shows but not the top part with buttons. Here are the changes I made in the java file.

Attachments:
Last edited by AB4586170 at 23:55 Oct 05, 2018.
jlopez172
Posts: 6
Posted 00:20 Oct 06, 2018 |

It’s difficult for me to tell since I don’t have my computer with me right now but try setting the button sizes this way button.setPrefSize(50.0,30.0) and in case you don’t still see them you can try changing the size of the hbox as well but much bigger like for example hbox.setPrefSize(225.0,40.0) I guess the errors must come the buttons

AB4586170
Posts: 19
Posted 00:53 Oct 06, 2018 |

Finally Working. Thank you so much.

Attachments:
abram92714
Posts: 8
Posted 23:28 Oct 06, 2018 |

how did you get your buttons to appear? for me, my redo button only appears in the top left corner of my grid and I have no clue why

Attachments:
Last edited by abram92714 at 23:29 Oct 06, 2018.
AB4586170
Posts: 19
Posted 23:32 Oct 06, 2018 |

Would you mind if you do it this way?

hbox.getChildren().addAll(undo, redo);

Maybe it'll work.

AB4586170
Posts: 19
Posted 23:33 Oct 06, 2018 |

And have you yet assigned the functions for the buttons? If so, where does it go? Any if-else loops necessary?

abram92714
Posts: 8
Posted 23:34 Oct 06, 2018 |

i did that my hbox i just called box

 

abram92714
Posts: 8
Posted 23:35 Oct 06, 2018 |

i added them in i looked back and i guess I didnt save my last version