Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Add tabs dynamically during runtime

 
Ranch Hand
Posts: 167
1
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 167
1
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic