Forums Register Login

Add tabs dynamically during runtime

+Pie Number of slices to send: Send
Hello,

My project is runnable and is on Git here: https://github.com/EasyG0ing1/CountdownTimer

What I would like to do with this application, is add the ability to create new tabs during runtime so that I can add more countdown timers. I’ve googled around and have found solutions to adding tabs during project initialization via multiple fxml files, or adding controls dynamically etc., but nothing that talks about how to basically ‘cookie cutter’ tabs to the program ... effectively duplicating the tab thats there, just adding more of them.

Any input would be much appreciated.

Mike Sims
+Pie Number of slices to send: Send
Press the button to add new tabs dynamically to the tab pane.

It's pretty easy. TabPane has an observable list of tabs - on an action event, you create a new tab and add it to the list and the new tab will be displayed in the order in which it was added to the list (e.g. if it was appended to the list, the new tab will be the last tab, if it was prepended to the list, the new tab would be the first tab). The selection model of the tabPane is queried and the new tab is set to selected so focus transfers directly to the new tab (if you wanted to leave the user on the existing tab, then you don't need to manipulate the selection model).

Here I just create the tab content dynamically in code, but you could also load the tab content up from an FXML file when the button action event is received.

+Pie Number of slices to send: Send
 

John Damien Smith wrote:Here I just create the tab content dynamically in code, but you could also load the tab content up from an FXML file when the button action event is received.


OK, so then when I am accessing controls on the new tab, is there some kind of an index number indicating which control on which tab I’m accessing? Or is it simply based on which tab has focus at any given moment in time?

Thank you very much for the code, I’ll play with it and see how it fits into my app.

Michael Sims
+Pie Number of slices to send: Send
> OK, so then when I am accessing controls on the new tab, is there some kind of an index number indicating which control on which tab I’m accessing? Or is it simply based on which tab has focus at any given moment in time?

Sorry, I can't understand this question.
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 9571 times.
Similar Threads
Problem updating main thread JavaFX control from custom Task
Countdown timer in java
CountDown Timer
Timer function in JSP
Help with using TableView and FXML
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:22:45.