Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add tabs dynamically during runtime

 
Michael D Sims
Ranch Hand
Posts: 70
1
Chrome Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Michael D Sims
Ranch Hand
Posts: 70
1
Chrome Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic