Reusing Panel code in each tabs on a tabbed pane
Hi
Im current developing an app which has two tabs (in the future there may be more added) which have to exact same variables, fields, Jtables, and so on.
currently i have named everything textbox1 and textbox2, and i pass in a port number to each method used.
just wondering if theres a way i can set a panel to show twice (or as many times as needed) on each tab of the JTabbedPane. This will help me stop repeating code.
Thanks
Kurt
Re: Reusing Panel code in each tabs on a tabbed pane
What you probably want to do is make an Object that contains everything under a single tab. Then just create a new instantiation of that Object for each tab, passing in whatever you want into the constructor.
Re: Reusing Panel code in each tabs on a tabbed pane
How would i go about doing this. currently everthing is added to the panel and the panel is added to the tab but i tried adding the same panel to the different tabs but it didnt work.
Thanks
Kurt
Re: Reusing Panel code in each tabs on a tabbed pane
No, you don't want to add the same panel to the tab, it doesn't work that way (which you discovered). Components can only be added to one Container.
What you could do it write a class that contains (or extends) the JPanel and includes all of the Components that get added to it. Then you create multiple instances of that class and add those instances to the tab.
Re: Reusing Panel code in each tabs on a tabbed pane
Right! I have this now.
I created a seperate class which holds the panel with all the components and added two instances like you said.
I had to create an array to pass the parameters but it works
thanks for your help
Kurt