Add New TabPanel with Controls

How do I add a new panel to a tabpanel widget and populate the new panel with widgets?

I know I can .Append, but how do I make sure I’m adding the new controls to the new panel?

For normal controls, set Parent and PanelIndex. For ContainerControls, use EmbedWithin.

The following code doesn’t work. Am I going about this correctly?

      dim newTextArea as TextArea
      dim newTabPanel as TabPanel
      
      newTextArea = New TextArea
      newTabPanel = new TabPanel
      
      newTextArea.Left = 0
      newTextArea.Top = 0
      newTextArea.Width = newTabPanel.Width
      newTextArea.Height = newTabPanel.Height
      newTextArea.LockBottom = True
      newTextArea.LockTop = True
      newTextArea.LockLeft = True
      newTextArea.LockRight = True
      system.DebugLog "newTextArea is now locked down"
      
      newTabPanel.Parent = tabpanel_Documents
      system.DebugLog "newTabPanel parent is now tabpanel_Documents"
      
      newTextArea.Parent = newTabPanel

No - basically you cant make that work that way.
But I assume you’ve read the user guides ?
Start with that as it will save you a ton of time as it covers a lot of very common questions.

[quote=224225:@Christopher Lester]The following code doesn’t work. Am I going about this correctly?

[code]
dim newTextArea as TextArea
dim newTabPanel as TabPanel

  newTextArea = New TextArea
  newTabPanel = new TabPanel
  
  newTextArea.Left = 0
  newTextArea.Top = 0
  newTextArea.Width = newTabPanel.Width
  newTextArea.Height = newTabPanel.Height
  newTextArea.LockBottom = True
  newTextArea.LockTop = True
  newTextArea.LockLeft = True
  newTextArea.LockRight = True
  system.DebugLog "newTextArea is now locked down"
  
  newTabPanel.Parent = tabpanel_Documents
  system.DebugLog "newTabPanel parent is now tabpanel_Documents"
  
  newTextArea.Parent = newTabPanel

[/code][/quote]

If you create these controls on a Container Control and dynamically embed that into a window then you will be on the right track. Norman is spot on as their User guide is very well written on topics like this.

I’ve read a lot of Xojo documentation and watched a bunch of tutorial videos. For this incident, I’ve searched the documentation and forum, but I can’t find the appropriate pieces for this particular issue.

I can add the new TabPanel with Append, but then how do I get the new panel’s index, so then I can use it to assign it as a Parent? My initial attempt (above) was to create the new panel and then add controls to it and then add it to the tabpanel, but that doesn’t work that way, apparently.

I’m very willing to read the relevant content, I just can’t seem to find it. What search term could I use in the forum or docs to bring up relevant hits? Or what page should I reference?

If my reading comprehension is lacking, it should improve over time. :slight_smile:

Thank you!

There are numerous PDF’s guide in the Documentation folder next to your install of Xojo
“Control Sets and Dynamic Controls” in User Guide User Interface should cover adding a new instance
This is covered in there

The docs are making their way to developer.xojo.com but may not be quite completely moved

[quote=224249:@Norman Palardy]“Control Sets and Dynamic Controls” in User Guide User Interface should cover adding a new instance
This is covered in there[/quote]

Normal, are you talking about the video tutorial? I watched it. (I’ve also read Book 2 in the User Guides.) It doesn’t tell me how to obtain a new TabPanel’s control ID so I can make it the parent of a new TextArea control. That’s where I’m stuck: getting the control ID of the new TabPanel to use it as a Parent for a TextArea.

Thank you!

I like to think I’m normal :slight_smile:

Have a look at the example Desktop > Controls > ControlSets
Thats how to add a control dynamically
But you HAVE to have an instance on the window already

You CANNOT make a control with NEW like your original post showed that will function properly
I said the right off the bat

You don’t need the tabpanel’s control ID (whatever that is). Assign the tabpanel directly to the textarea’s Parent property. You might be thinking of the PanelIndex, which you can get with the tabpanel’s PanelCount.
Add a TextArea to the page and make it a control set. For example, if your control set is TextArea1:

TabPanel1.Append "New Tab"
dim newtextarea as TextArea1 
newtextarea = new TextArea1
newtextarea.Parent = TabPanel1
newtextarea.PanelIndex = TabPanel1.PanelCount-1

Question: why are you creating a brand new tabpanel instead of adding a tab to an existing one?

Hahahaa! Oops! I’ll leave it that way, for posterity’s sake.

Does that include tabs? Or just the TextArea/other controls? I would have thought tabs didn’t require a control set, since they seem to be automagically in a control set.

[quote=224281:@Tim Hare]You don’t need the tabpanel’s control ID (whatever that is). Assign the tabpanel directly to the textarea’s Parent property. You might be thinking of the PanelIndex, which you can get with the tabpanel’s PanelCount.
Add a TextArea to the page and make it a control set. For example, if your control set is TextArea1:

newtextarea.Parent = TabPanel1 newtextarea.PanelIndex = TabPanel1.PanelCount-1 [/quote]

Ah. OK. I did the “newtextarea.Parent = TabPanel1” at some point, but didn’t know to do the PanelIndex property for the newtextarea. I’ll give that a try and see how it goes.

I guess I hadn’t wrapped my brain around how Xojo does tabs and tabpanels. But your code above makes it clearer. I was thinking I needed to obtain the ID of the particular TabPanel to put controls on it. Instead, I just add it to the TabPanel main controller (with Parent) and then set the PanelIndex of the control. Yes, that’s exactly what you said in your first response in this topic, but it was out of context for me so I was confused.

Thanks so much!

[quote=224431:@Christopher Lester]
Does that include tabs? Or just the TextArea/other controls? I would have thought tabs didn’t require a control set, since they seem to be automagically in a control set.[/quote]
Tabs re not controls in and of themselves
They are an intrinsic part of a tab panel

And no you cant add or remove tabs at runtime
http://documentation.xojo.com/index.php/TabPanel
You’ll see that panelcount is read only

@Tim Hare, I think if you put a small code sample, like you did in a subsequent reply, this would be more clear to the n00bs like me.

Thank you!

This code doesn’t seem to be working. Can you guys see if there’s a problem with it:

      dim newTextArea as TextArea

      'add the new page to the tabpanel      
      tabpanel_Documents.Append newDoc
      'get its PanelIndex
      usepanel = tabpanel_Documents.PanelCount - 1
      
      newTextArea = New TextArea

      'assign the new TextArea to the tabpanel page      
      newTextArea.Parent = tabpanel_Documents
      newTextArea.PanelIndex = usepanel

The code gets run (I have a MsgBox at the end), but I can’t see the TextArea on the TabPanel page.

Yes
I already said 3 times THIS WONT WORK, why it wont work and what you need to read to see how to do it using control sets

[quote=224463:@Norman Palardy]Yes
I already said 3 times THIS WONT WORK, why it wont work and what you need to read to see how to do it using control sets[/quote]

Wow. Sorry. I thought I was doing it right according to this forum’s input. Yikes.

I GOT IT WORKING. Thank you for the help.

Very curious to see how you got that working. Could you post the code, please ?

One SMALL but significant change (thanks to Normal Norman’s patient and no doubt exhausting help):

dim newTextArea as TextArea
    
tabpanel_Documents.Append newDoc
usepanel = tabpanel_Documents.PanelCount - 1
    
newTextArea = New txt_Document
    
newTextArea.Parent = tabpanel_Documents
newTextArea.PanelIndex = usepanel

I have a VERY strong suspicion this isn’t going to work right
But …